【问题标题】:TypeError: post_request() missing 2 required positional arguments: 'token' and 'uuid'类型错误:post_request() 缺少 2 个必需的位置参数:\'token\' 和 \'uuid\'
【发布时间】:2022-08-05 20:46:10
【问题描述】:

因此,作为信息,我尝试制作一个脚本来检查 SessionID 在 Minecraft 中是否有效,然后将其发送到 webhook。

File \"c:\\Users\\PC\\Desktop\\RandomShit\\dhook.py\", line 43, in <module>
    isValid = post_request()
TypeError: post_request() missing 2 required positional arguments: \'token\' and \'uuid\'

所以这是代码,但由于某种原因它不起作用,我对 python 和一般编码很陌生,需要帮助。

from cgitb import text
from dhooks import Webhook, Embed
import requests
import json

hook = Webhook(\'https://discord.com/api/webhooks/1000036496658669619/OChDQ2Whz86jlIrXDelDUUybjQ0DPXkEWRB9QRInBJb18Ww4W-NPo_ZM_fVwnHQ88gh0\')
token = \"Token Here\"
uuid = \"UUID Here\"

def send(token, uuid):
#embed json
  embed = Embed(
    title= \"Token Validator\",
    color=0x68228B,
    timestamp=\'now\'  # sets the timestamp to current time
    )



  embed.add_field(name=\'UUID\', value=uuid, inline=\'false\')
  embed.add_field(name=\'Token\', value=token, inline=\'false\')


  hook.send(embed=embed)

def post_request(token, uuid):
    url = \"https://sessionserver.mojang.com/session/minecraft/join\"
    payload = {
        \"accessToken\": token,
        \"selectedProfile\": uuid,
        \"serverId\": uuid
    }
    headers = {
        \'Content-Type\': \"application/json\"
    }
    response = requests.post(url, data=json.dumps(payload), headers=headers)
    if response.status_code == 204:
        return True
    else:
        print(response.text)
        return False

isValid = post_request()
if isValid:
    print(\"token is valid\")
    send(token, uuid)
else:
    print(\"token is invalid\")

感谢我能得到的所有帮助。

    标签: python


    【解决方案1】:

    您忘记将 token, uuid 传递给 request 函数

    from cgitb import text
    from dhooks import Webhook, Embed
    import requests
    import json
    
    hook = Webhook('https://discord.com/api/webhooks/1000036496658669619/OChDQ2Whz86jlIrXDelDUUybjQ0DPXkEWRB9QRInBJb18Ww4W-NPo_ZM_fVwnHQ88gh0')
    token = "Token Here"
    uuid = "UUID Here"
    
    def send(token, uuid):
    #embed json
      embed = Embed(
        title= "Token Validator",
        color=0x68228B,
        timestamp='now'  # sets the timestamp to current time
        )
    
    
    
      embed.add_field(name='UUID', value=uuid, inline='false')
      embed.add_field(name='Token', value=token, inline='false')
    
    
      hook.send(embed=embed)
    
    def post_request(token, uuid):
        url = "https://sessionserver.mojang.com/session/minecraft/join"
        payload = {
            "accessToken": token,
            "selectedProfile": uuid,
            "serverId": uuid
        }
        headers = {
            'Content-Type': "application/json"
        }
        response = requests.post(url, data=json.dumps(payload), headers=headers)
        if response.status_code == 204:
            return True
        else:
            print(response.text)
            return False
    
    isValid = post_request(token, uuid) # add this here
    if isValid:
        print("token is valid")
        send(token, uuid)
    else:
        print("token is invalid")
    

    【讨论】:

      猜你喜欢
      • 2022-06-28
      • 2019-11-16
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 2022-01-11
      相关资源
      最近更新 更多