#_*_coding:骆驼翔子-8_*_ 2024-08-11 21:35 采纳率: 93.3%
浏览 1

pythonpost请求出错

pythonpost请求出错

浏览器f12界面如下

img

内容如下


请求 URL:
https://t24z.fgf963o.work/jindex.php
请求方法:
POST
状态代码:
200 OK
远程地址:
66.203.155.25:443
引用站点策略:
strict-origin-when-cross-origin
Cache-Control:
no-store, no-cache, must-revalidate
Connection:
keep-alive
Content-Encoding:
gzip
Content-Length:
227
Content-Type:
text/html; charset=utf-8
Date:
Sun, 11 Aug 2024 13:16:14 GMT
Expires:
Thu, 19 Nov 1981 08:52:00 GMT
Pragma:
no-cache
Server:
qq.com
Vary:
Accept-Encoding
POST /jindex.php HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Connection: keep-alive
Content-Length: 118
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: PHPSESSID=juqbilrp6i7b6ddvqalktop509
Host: t24z.fgf963o.work
Origin: https://t24z.fgf963o.work
Referer: https://t24z.fgf963o.work/index.php?op=view&class=2&spcode=SFE6995&productsid=35445
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0
X-Requested-With: XMLHttpRequest
sec-ch-ua: "Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"

我的代码如下


import requests
import json
url = "https://t24z.fgf963o.work/jindex.php"

data = {
    "Accept": "application/json, text/javascript, */*; q=0.01",
    "Accept-Encoding": "gzip, deflate, br, zstd",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Connection": "keep-alive",
    "Content-Length": "118",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Cookie": "PHPSESSID=juqbilrp6i7b6ddvqalktop509",
    "Host": "t24z.fgf963o.work",
    "Origin": "https://t24z.fgf963o.work",
    "Referer": "https://t24z.fgf963o.work/index.php?op=view&class=2&spcode=SFE6995&productsid=35445",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
    "X-Requested-With": "XMLHttpRequest",
    "sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"',
}

res = requests.post(url=url, data=json.dumps(data))
print(res.text)

但是返回jmodules error。
其中data=json.dumps(data)和data=data和json=json.dumps(data)和json=data都试过了,都不行。

  • 写回答

2条回答 默认 最新

  • 一直免费一直爽 2024-08-11 21:35
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    要解决这个问题,首先确保你的Python环境是最新版本的,并且已经安装了requests库。其次,你需要在发送HTTP POST请求时正确地设置Content-Type头部为application/x-www-form-urlencoded。此外,你应该尝试将data字典转换为JSON格式后再进行发送。

    以下是修复上述问题的方法:

    import requests
    import json
    
    # 正确的请求参数
    url = "https://t24z.fgf963o.work/jindex.php"
    data = {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection": "keep-alive",
        "Content-Length": "118",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Cookie": "PHPSESSID=juqbilrp6i7b6ddvqalktop509",
        "Host": "t24z.fgf963o.work",
        "Origin": "https://t24z.fgf963o.work",
        "Referer": "https://t24z.fgf963o.work/index.php?op=view&class=2&spcode=SFE6995&productsid=35445",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
        "X-Requested-With": "XMLHttpRequest",
        "sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"'
    }
    
    response = requests.post(
        url=url,
        data=json.dumps(data),
        headers={"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"},
    )
    
    # 打印响应结果
    print(response.text)
    

    这段代码会正确地处理数据并发送到指定的URL。请注意,这只是一个基本示例,实际应用中可能还需要考虑更多的错误处理和异常情况。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月11日

悬赏问题

  • ¥15 ocr识别纯数字会将数字翻转,并且会识别成字母
  • ¥30 WPF如何实现动态Y轴
  • ¥15 关于遇到一个python,django,redis,uwsgi,nginx搭的一个企业微信修改AD密码的平台的问题!
  • ¥15 读取parquet文件某一列的数据但是输出是整个列名和格式
  • ¥15 机动目标 制导律建模问题
  • ¥100 求Java socks 转发实现Demo
  • ¥20 随身WiFi移动网络访问不了
  • ¥50 RAD_XE11.3获取android11手机的IMEI码
  • ¥15 linux的gcc命令报错
  • ¥20 如何再GIS用海岸线建立缓冲区