You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用requests实现图片投票?排查现有代码问题

问题描述

尝试给某网站图片投票但未生效,目标图片地址:https://woobox.com/nvk7uh/gallery/B47CxJE1PoU,已通过网络监听到投票请求的Payload和Headers,但编写的requests代码(因不清楚如何获取图片ID未添加该参数)未达到预期效果,代码如下:

import requests

link = "https://woobox.com/nvk7uh/gallery/B47CxJE1PoU"
request_url = 'https://woobox.com/nvk7uh/vote/add'
session = requests.session()

response = session.get(link, headers=fake_header)
print(response.status_code)

vote_payload = {
    'signed_request': 'false'
}
    
vote_headers = {
    'accept': '*/*',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
    'referer': link,
    'x-requested-with': 'XMLHttpRequest'
}

voter_response = session.post(request_url, data=vote_payload, headers=vote_headers)
print('Vote Status: ' + str(voter_response.status_code))
print(voter_response.text)
time.sleep(3)

代码存在的问题

  • 缺少核心投票目标参数:投票接口必须指定要投的图片,目标URL里的B47CxJE1PoU就是图片ID,需要把它加入vote_payload,比如添加'entry_id': 'B47CxJE1PoU'(具体键名以你监听的Payload为准,可能是entry_id或类似字段)。
  • 未定义fake_header变量:代码里用了fake_header但没定义,会直接报错,无法正常获取会话信息,需要补全这个Header的内容,或者替换成你监听的请求头。
  • signed_request参数无效:你设置的'false'不符合实际要求,真实的signed_request应该是你监听Payload里的有效签名值,用假值会被服务器拒绝。
  • 未导入time模块:代码最后调用time.sleep(3)但没导入time,会抛出模块未找到错误,需要在开头添加import time。
  • 请求头不完整:你监听的Headers里应该还有其他必要字段(比如content-type、Cookie等),当前的vote_headers缺失关键信息,服务器会判定为非法请求。

内容的提问来源于stack exchange,提问作者NoobCoding

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 18:16:06