Código
from datetime import datetime, timedelta
import requests
import os
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S.00Z"
end_time = datetime.now()
start_time = (end_time + timedelta(-1)).date().strftime(TIMESTAMP_FORMAT)
query = "data science"
tweet_fields = "tweet.fields=author_id,conversation_id,created_at,id,in_reply_to_user_id,public_metrics,lang,text"
user_fields = "expansions=author_id&user.fields=id,name,username,created_at"
url_raw = f"https://labdados.com/2/tweets/search/recent?query={query}&{tweet_fields}&{user_fields}&start_time={start_time}&end_time={end_time}"
bearer_token = os.environ.get("BEARER_TOKEN")
headers = {
"Authorization": "Bearer {}".format(bearer_token),
}
response = requests.request("GET", url_raw, headers=headers)
print(response.text)
Retorno
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>