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

问题描述

我正在尝试使用 Python 的请求为 Ubisoft 制作用户名检查器。 当我运行我的代码时,我总是得到一个状态代码 200,它应该表明用户名可用,即使用户名被占用。我检查了 request link,它说:

{"moreInfo":"","errorCode":3,"httpCode":401,"errorContext":"Shipyard.Profiles.Services","message":"缺少授权头","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 将此作为应采用的用户名用户名 = 测试)的输出

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 将其作为应该可用的用户名用户名 = test815581m)的输出

200
{"profiles":[]}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)