Trying to use this
but when I do this I get a 401 on my status code
How can I get the data and print them out?
Trying to use this
but when I do this I get a 401 on my status code
How can I get the data and print them out?
He’s not using HttpService though. He’s using Python Requests?
My apologies, I was just so used to expecting lua.
Sorry for the mix up!
Well that’s not the issue, the http status code is still 401. Which means he doesn’t have access to request to it. I don’t use python so I don’t know if he is doing it the wrong way.
@n_cy I don’t know if this will help or not. While it may or may not give you access to it, I don’t know of. But I found this looking around.
# import urllib library
from urllib.request import urlopen
# import json
import json
# store the URL in url as
# parameter for urlopen
url = "https://link.com"
# store the response of URL
response = urlopen(url)
# storing the JSON response
# from url in data
data_json = json.loads(response.read())
# print the json response
print(data_json)
No, im fairly certain the usage of the requests module is correct.
It probably has to either be something to do with the api being deprecated, or arguments missing or something related to the request itself.
Other than a 401, is an error json reponse sent? If so, what does it contain?
Well a 401 indicates unauthorized. Maybe you need to be logged in. Are you setting the .ROBLOSECURITY
cookie?
Man’s just abandoned his whole question. He ain’t even speaking xd
To use most API endpoints, you’ll need a certain cookie. I really don’t want to explain how to get that cookie because anyone with that cookie can access your Roblox account, and that’s bad.
cookies = {'.ROBLOSECURITY': 'PLEASE KEEP THIS SECRET'}
r = requests.get("url", cookies=cookies)
The API isn’t intended to be used by anyone except Roblox, so things could break at any time. For some requests (usually POST
), you’ll also need to set the x-csrf-token
header.
headers = {'x-csrf-token': '????????'}
Whenever you encounter one of those endpoints, you’ll receive an error message with your x-csrf-token
in response headers.
# assuming r is a request that just failed
headers = {'x-csrf-token': r.headers['x-csrf-token']}
This is not intended to be a full guide to interacting with the Roblox API using Python because surprisingly, I don’t even know Python! and you REALLY SHOULD NOT BE USING THE API UNLESS YOU ABSOLUTELY KNOW EXACTLY WHAT YOU’RE DOING AND WHY YOU NEED IT. AND
I will now return to being dead
what’s a roblo security cookie and what do I need to do with it?
Not sure if it applies in this case, but this is that “certain cookie” that bytechan was talking about.
It basically allows you to login to your account. But make sure to NEVER give it away to ANYONE. Because that is a SUREFIRE way of getting hacked.
You can probably search up a tutorial on how to get it. Basically, press f12 on roblox.com. Click application, click cookies, and find it.
Anyways, you probably need a x-csrf-token. Not sure exactly on how to get it but you might be able to get it by sending a get request to the frontend trading page, then just extract the cookie and set it in your request each time you make a new request
You need to set the headers with your cookie
make a request to get your x-csrf-token
and then make a final get request with your cookie and the token to receive the data eventually
If you don’t know how to get your cookie, simply just look it up on google/youtube
ALSO DON’T SHARE YOUR COOKIE, people will be able to log in your account!
I hope this works or helped a little
import requests
cookie = ".ROBLOSECURITY="
requests.session()
url = "https://trades.roblox.com/v1/users/ID_OF_RECEIVER/can-trade-with"
s = requests.get(url, headers={
"cookie":cookie
})
a = requests.get(url, headers={
"x-csrf-token":s.headers["x-csrf-token"],
"cookie":cookie,
"accept": "application/json"
})
print(a)
print(a.headers)