api
api copied to clipboard
Bungie oauth request causes cloudflare error
Hello, I am new to this so apologize in advance if this is an obvious error but I'm trying to test a basic program to get vendor data using OAuth 2. Every time I do it however I receive what looks like a Cloudflare error 500 and I'm not sure why.
This is the response I get:
and this is the my code (with sensitive info removed)
import requests
import aiohttp
import requests
import aiohttp
characterID="2305843009345815489"#my warlock
destinyMembershipID="4611686018467931696"
membershipType="3"
vendorHash = "672118013" #banshee-44
token = "my-token" #oauth token from https://www.bungie.net/en/OAuth/Authorize?client_id=40978&response_type=code
headerParameters = {
"X-API-Key": "my-api-key",
"Authorization":"Bearer " + token
}
#template URLS that all endpoints start with
DestinyURLBase = "https://www.bungie.net/Platform"
#Make an GET request to api and return json
def get_api_request(url):
try:
#get api request
res = requests.get(url, headers=headerParameters)
return res.content
#parse to json
#store json response
#self.apiResponseJson = jsonResponse
except aiohttp.client_exceptions.ClientResponseError as e:
print("ERROR: Could not connect to Bungie.net Endpoint")
#test with charcter info
apiUrl = DestinyURLBase + "/Destiny2/3/Profile/4611686018467931696/Character/2305843009345815489/Vendors/" + vendorHash +"/?components=402" #format url data
print(apiUrl)
apiResponse = get_api_request(apiUrl)
print(apiResponse)
And this is the output i get
> https://www.bungie.net/Platform/Destiny2/3/Profile/4611686018467931696/Character/2305843009345815489/Vendors/672118013/?components=402
> b'\xef\xbb\xbf<!DOCTYPE html>\r\n<html>\r\n<head>\r\n\t<meta charset="utf-8" />\r\n\t<title>Bungie.net: 500 Internal Server Error</title>\r\n\t<link type="text/css" rel="stylesheet" href="/css/error.css" />\r\n\t<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">\r\n</head>\r\n<body>\r\n\t<header>\r\n\t\t<a id="logo" href="/"></a>\r\n\t</header>\r\n\t<div class="container">\r\n\t\t<h1>500: Internal Server Error</h1>\r\n\t\t<div class="message">\r\n\t\t\t<p>\r\n\t\t\t\tSomething bad has happened. It\xe2\x80\x99s not you. It\xe2\x80\x99s us. We all make mistakes, and this one was totally ours.<br />\r\n\t\t\t\t<br />\r\n\t\t\t\tClick the back button to go back where you came from.<br />\r\n\t\t\t\t<br />\r\n\t\t\t\tWe don\xe2\x80\x99t want you to see us like this.\r\n\t\t\t</p>\r\n\t\t</div>\r\n\t\t<div class="footer">\r\n\t\t\t<p>\r\n\t\t\t\tThis error has automatically been logged and we
are aware of your plight.<br />\r\n\t\t\t\t<br />\r\n\t\t\t\tHTTP Client Error; 500 Internal Server Error\r\n\t \r\n\t\t\t</p>\r\n\t\t\t::CLOUDFLARE_ERROR_500S_BOX::\r\n\t\t</div>\r\n\t</div>\r\n<script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652eace1692a40cfa3763df669d7439c1639079717194" integrity="sha512-Gi7xpJR8tSkrpF7aordPZQlW2DLtzUlZcumS8dMQjwDHEnw9I7ZLyiOj/6tZStRBGtGgN6ceN6cMH8z7etPGlw==" data-cf-beacon=\'{"rayId":"73528d4daff707ba","token":"d9037c24bdf84e8bb712f1597ca7e783","version":"2022.6.0","si":100}\' crossorigin="anonymous"></script>\n</body>\r\n</html>\r\n'
Lemme know if you guys need any more info!
Thanks!
I could be completely off-base here, but I see this error from Cloudflare when testing scripts when I don't send along a User-Agent:
header. Cloudflare automatically blocks many common HTTP library client IDs, such as libwww-perl(LWP).
There's actually a recommended User-Agent string format Bungie suggests.
Here's the comments I have over the code that builds mine:
# define complete User Agent
# Per Bungie:
# “AppName/Version AppId/appIdNum (+webUrl;contactEmail)”
# For example: User-Agent: Really Cool App/1.0 AppId/##### (+www.example.com;[email protected])
Try that and see if it helps?
@soren42 that didnt seem to work, is it possible i could be missing some other headers?
Ok so I figured it out and it was honestly a stupid mistake on my part. Is it possible to generate a token that doesn't expire since my project is personal?
@lulamae12 would you mind sharing what the stupid mistake was? I fear I hit the same issue when my token expires
sorry for the late response, I wasn't sending an auth request correctly. I made this small tool to help me in the future, maybe it will be of use to you?
https://github.com/lulamae12/D2Bearer-Cli