gpt4 book ai didi

python 请求登录后得到响应代码 500

转载 作者:行者123 更新时间:2023-11-28 18:39:07 25 4
gpt4 key购买 nike

code below:
#!/bin/env python
# -*- coding: utf-8 -*-

import sys
import requests

#headers = {'User-Agent': 'Mozilla/5.0',"ContentType":"text/xml;charset=utf-8"}
payload = {
'userName':'myusername',
'password':'mypasswd',
'callback':'jQuery17209257929018213263_1425826216682',
'redirectURL':'http://www.10010.com',
'redirectType':'01',
'productType':'01',
'pwdType':'01',strong text
'rememberMe':'01'
}
link = 'https://uac.10010.com/portal/Service/MallLogin'
s = requests.Session()
resp = s.post(link,data=payload)
print resp
print resp.content
print resp.text

当我运行代码时,我得到了响应 500,但是当我在浏览器中复制带有参数的链接时,它起作用了,我可以登录了。我找不到原因。我需要帮助,谢谢!

最佳答案

试试这个。

header_content = {'Content-type': 'application/json'} 
js_data = json.dumps({'username': 'myusername',
'password': 'mypasswd',
'callback':'jQuery17209257929018213263_1425826216682',
'redirectURL':'http://www.10010.com',
'redirectType':'01',
'productType':'01',
'pwdType':'01',
'rememberMe':'01'})
response = requests.post(link, data=js_data, headers=header_content, verify=False)

if response.status_code == 200:
print(response.content)

您需要在 header 中指定内容,在您的情况下它是 json。此外,当您通过 https 执行请求时,证书验证可能会导致问题,因此请通过“verify=False”关闭验证。 json 格式错误也可能是 500 的原因,因此为了确保您传递的是适当的 json 对象,我建议使用 json.dumps()。希望能帮助到你。问候!

关于python 请求登录后得到响应代码 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28928437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com