0

i am making a website where you can link your ROBLOX account to the website with only the username but i have had an error which i dont know how to fix it. If you know how to fix this error please tell me since this has been very frustrating.

** Traceback:**

Traceback (most recent call last):
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

During handling of the above exception (Expecting value: line 1 column 1 (char 0)), another exception occurred:
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Gebruiker\Desktop\Ro-Sky Front-end\base\views.py", line 88, in auth
    if robloxpy.User.External.DoesNameExist(request.POST['username']) == "Unavailible":
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\site-packages\robloxpy\User\External.py", line 217, in DoesNameExist
    return response.json()
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

This is the code the error should be coming from:

def auth(request):
    if not request.user.is_authenticated:
        isAvailible = None
        code = None
        if request.method == "POST":
            isAvailible = False
            if robloxpy.User.External.DoesNameExist(request.POST['username']) == "Unavailible":
                user = str(request.POST['username']).lower()
                data = requests.get(f'https://api.roblox.com/users/get-by-username?username={user}').json()
                print(user)
                user = data['Username']
                id = data['Id']
                desc = robloxpy.User.External.GetDescription(id)


                isAvailible = True
                user = str(request.POST['username']).lower()
                print(user)
                print(User.objects.filter(username=user))
                if User.objects.filter(username=user).exists():
                    code = User.objects.get(username=request.POST.get('username')).auth_code

                    if desc != None and User.objects.get(username=user).auth_code in desc:
                        userchange = User.objects.get(username=user)
                        userchange.auth_code = randomVerify()
                        userchange.save()
                        login(request, User.objects.get(username=user))
                        return redirect('home')
                else:
                    id = requests.get(f'https://api.roblox.com/users/get-by-username?username={user}').json()['Id']
                    created_user = User(username=user, rbx_id=id)
                    created_user.save()
                    code = created_user.auth_code

        content = {"available": isAvailible, "code": code}

        print(isAvailible)

        return render(request, 'auth.html', content)
    else:
        return redirect('dashboard')

def logout_acc(request):
    logout(request)
    return redirect('auth')


def welcome(request):
    if request.user.is_authenticated:
        id = requests.post(f'https://users.roblox.com/v1/usernames/users', data={
        "usernames": [
            request.user.username
        ],
        "excludeBannedUsers": True
        }).json()["data"][0]['id']
        avatar_uri = f"https://www.roblox.com/headshot-thumbnail/image?userId={id}&width=60&height=60&format=png"
        content = {'avatar_uri': avatar_uri}
        return render(request, 'welcome.html', content)
    else:
        return redirect('auth')

0 Answers0