#๐Ÿ”’ 401 Authorized Error Roblox api

106 messages ยท Page 1 of 1 (latest)

manic turret
#

I am trying to make a roblox image uploader using api, but when using the api i keep getting the 401 error and im not sure how to fix it

strong pantherBOT
#

@manic turret

Python help channel opened

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.

manic turret
#

Hello

rose mica
#

from 10 seconds of googling your request lacks authentication

#

for api requests

#

their codes are set in place

#

google <code> request code

manic turret
#

yeah but

#

it logs into my account first

#

and im 100% sure it does

rose mica
#

show code

#

(i dont know webbing)

manic turret
#
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

rose mica
#

lemme look

#

at the code

manic turret
#

๐Ÿ‘

rose mica
#

yeah i used the request lib

#

i actually know this

#

hmmm i think i just gotta google

rose mica
manic turret
#

what

#

?

#

wdym

rose mica
#
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
manic turret
#

that should work?

rose mica
#

it doesnt change the functionality

#

im still reading it gimme a few minutes

manic turret
#

alright thank you

rose mica
#

provide the whole traceback

manic turret
#

what?

#

im fairly new to python

#

sorry

rose mica
#

didnt you misspell ROBLOXSECURITY?

manic turret
#

no

#

it logs into the account

rose mica
#

session.cookies.update({".ROBLOSECURITY": cookie}) this?

manic turret
#

yes

#

thats what the cookie is called

#

roblosecurity

rose mica
#

aight

#

youre new to python but you know this

manic turret
#

see

#

it logs into the account

#

and gets its username

#

from the cookie

rose mica
#

is there no error?

manic turret
#

401 is the error

manic turret
rose mica
#

like a traceback

manic turret
rose mica
#

its because you only print the status code

manic turret
#

the api doesnt even go through

#

but

#

i just tried using another api

#

for the same thing

#

and i got the status code 200

manic turret
rose mica
#

i think it doesnt work since it has no rate limit

manic turret
#

my friend uses it

rose mica
#

but idk

manic turret
#

and it works for him

#

but hes using node js

rose mica
#

can you try ```py
print(str(response))
print(f"{response!r}")

manic turret
#

okay

rose mica
#

we got nothing, great

manic turret
#

im not sure why it doesnt work

#

idk what to do

rose mica
#

hold on

#

its the data paramater made wrong

manic turret
#

im not sure

#

this is what my friend did with the api in node js

still glade
#

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

manic turret
#

the welcome is just printing the username

still glade
#

Yes I get it, but it's at a different url

manic turret
#

yeah

still glade
#

Why 2 urls?

manic turret
#

1 for checking if the cookie is correct

#

and having a greeting

#

then the other for uploading the image

still glade
#

How do you know that the upload image endpoint is correct?

manic turret
#

how do i check

still glade
#

Idk, i've never used roblox

#

why do you think that endpoint is correct?

manic turret
#

along with the api

#

thats in node js

#

my friend doesnt know python

#

so its hard for us to help it work in python

still glade
#

Tell your friend to dump out the other headers that he's sending

#

...formData.getHeaders()

manic turret
#

okay

#

he gets online late

#

so i'm going to need to wait on him

strong pantherBOT
#
Python help channel closed

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.