Python请求:“缺少授权标头”

2024-09-27 19:31:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python的请求为育碧软件制作一个用户名检查器。 当我运行我的代码时,我总是得到一个状态代码200,这应该表明用户名是可用的,即使使用了用户名。我查了一下request link上面写着:

{"moreInfo":"","errorCode":3,"httpCode":401,"errorContext":"Shipyard.Profiles.Services","message":"The Authorization header is missing","environment":"prod","additionalDetails":{},"transactionTime":"2021-05-24T17:27:50.9065561Z","transactionId":"5d4edaf2-8e8f-4e3f-9736-fce6aea82e32"}

但是,我在代码中添加了'Authorization':token,令牌是登录后从权威网站获得的输入

我的代码:

import requests
import json

def check():
    username = input("What name to check? :")
    print(" ")
    token = input("Enter token: ")

    r = requests.get("https://public-ubiservices.ubi.com/v2/profiles?nameOnPlatform=" + username + "&platformType=uplay", headers = {
                'Method':'GET',
                'Authority':'public-ubiservices.ubi.com',
                'Ubi-AppId':'c5393f10-7ac7-4b4f-90fa-21f8f3451a04',
                'Authorization': token,
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
                'Ubi-RequestedPlatformType':'uplay',
                })
    print(r.status_code)
    print(r.text)

print("Press ENTER to start checking")
input("")
check()

编辑:添加了r.text

r.text将此作为应采用的用户名(username=test)的输出

200
{"profiles":[{"profileId":"21067093-822e-497d-ae8a-5d171573f6c8","userId":"21067093-822e-497d-ae8a-5d171573f6c8","platformType":"uplay","idOnPlatform":"21067093-822E-497D-AE8A-5D171573F6C8","nameOnPlatform":"test"}]}

而r.text将其作为应该可用的用户名(username=test815581m)的输出

200
{"profiles":[]}

Tags: to代码textimporttokeninputcheckusername

热门问题