#๐ 401 Authorized Error Roblox api
106 messages ยท Page 1 of 1 (latest)
@manic turret
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hello
from 10 seconds of googling your request lacks authentication
for api requests
their codes are set in place
google <code> request code
import requests
import datetime
import time
img = 'image.png'
cookie=""
def welcome(session):
try:
bot = session.get('https://www.roblox.com/mobileapi/userinfo').json()["UserName"]
print(f"Welcome `{bot}`")
except:
print("Invalid cookie")
quit()
def get_token(session):
response = session.post('https://friends.roblox.com/v1/users/1/request-friendship')
if 'x-csrf-token' in response.headers:
return response.headers['x-csrf-token']
else:
print('x-csrf-token not found')
def upload(session, location):
headers={
"Requester": "Client",
"X-CSRF-TOKEN": get_token(session),
"Cookie": "",
}
response = session.post(f'https://apis.roblox.com/assets/user-auth/v1/assets', data=open(location, 'rb'), headers=headers)
print(response.status_code)
with requests.Session() as session:
session.cookies.update({".ROBLOSECURITY": cookie})
welcome(session)
upload(session, img)```
im trying to upload an image
it says my username
but gives an error when using the api
@rose mica do you think you will be able to help with this issue
๐
please type hint your function arguments first
import requests as req
import datetime
import time
img = 'image.png'
cookie=""
def welcome(session: req.Session):
try:
bot = session.get('https://www.roblox.com/mobileapi/userinfo').json()["UserName"]
print(f"Welcome `{bot}`")
except:
print("Invalid cookie")
quit()
def get_token(session: req.Session):
response = session.post('https://friends.roblox.com/v1/users/1/request-friendship')
if 'x-csrf-token' in response.headers:
return response.headers['x-csrf-token']
else:
print('x-csrf-token not found')
def upload(session: req.Session, location: str):
headers={
"Requester": "Client",
"X-CSRF-TOKEN": get_token(session),
"Cookie": "",
}
response = session.post(f'https://apis.roblox.com/assets/user-auth/v1/assets', data=open(location, 'rb'), headers=headers)
print(response.status_code)
with req.Session() as session:
session.cookies.update({".ROBLOSECURITY": cookie})
welcome(session)
upload(session, img)
``` here the function arguments are type hinted
that should work?
alright thank you
provide the whole traceback
didnt you misspell ROBLOXSECURITY?
session.cookies.update({".ROBLOSECURITY": cookie}) this?
is there no error?
401 is the error
this is all thats printed
like a traceback
only this
its because you only print the status code
the api doesnt even go through
but
i just tried using another api
for the same thing
and i got the status code 200
but i need to use the one in here, since it has no rate limit
i think it doesnt work since it has no rate limit
my friend uses it
but idk
can you try ```py
print(str(response))
print(f"{response!r}")
we got nothing, great
I don't really understand the code.... why is the welcome call going to a different endpoint than an upload call? an api call wouldn't have a CSRF token
CSRF is for web only
Yes I get it, but it's at a different url
yeah
Why 2 urls?
1 for checking if the cookie is correct
and having a greeting
then the other for uploading the image
How do you know that the upload image endpoint is correct?
how do i check
i was sent this
along with the api
thats in node js
my friend doesnt know python
so its hard for us to help it work in python
Tell your friend to dump out the other headers that he's sending
...formData.getHeaders()
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.