Iahve a deta.space website here: https://bonbastapi-1-z9030825.deta.app
This is python code I’m try to get some deta from this website:
def get_last_rate_task():
url = 'https://bonbastapi-1-z9030825.deta.app/latest'
try:
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'en-US,en;q=0.9,fa-IR;q=0.8,fa;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Host': 'bonbastapi-1-z9030825.deta.app',
'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"Linux"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
response.raise_for_status()
try:
data = response.json()
usd_data = data.get('usd', {})
usd_sell_price = usd_data.get('sell')
if usd_sell_price is not None:
ExchangeRate.objects.create(price=usd_sell_price, source='bonbast')
else:
logger.error(f"USD sell price not found in the response: {data}")
except ValueError as e:
logger.error(f"JSON decoding error: {e}, response content: {response.content}")
except requests.exceptions.HTTPError as http_err:
logger.error(f"HTTP error occurred: {http_err}, response content: {response.content}")
except requests.exceptions.RequestException as req_err:
logger.error(f"Request error occurred: {req_err}")
But unfortuently I get this error:
HTTP error occurred: 403 Client Error: Forbidden for url: https://deta.space/api/v0/auth/pass?redirect_uri=https%3A%2F%2Fbonbastapi-1-z9030825.deta.app%2Flatest, response content: b'<html>rn<head><title>403 Forbidden</title></head>rn<body>rn<center><h1>403 Forbidden</h1></center>rn<hr><center>cloudflare</center>rn</body>rn</html>rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn<!-- a padding to disable MSIE and Chrome friendly error page -->rn'
I treid to add this to headers:
'Cookie': 'deta_app_token=TOKEN FROM deta.space>settings>Authentication>Access Tokens',
But I got this error:
HTTP error occurred: 401 Client Error: Unauthorized for url: https://bonbastapi-1-z9030825.deta.app/latest, response content: b'Unauthorizedn'
explained above completely