调用Param Gaming注册API返回403状态码问题求助
我已经添加了接口请求所需的全部核心请求头,但调用Param Gaming的注册接口(https://paramgaming.com/api/v1/user/signup)时仍返回403(Forbidden)状态码。我是新手,对相关操作不太熟悉,按预期代码应该可以正常运行,以下是我的代码:
import requests # Define the URL of the form submission endpoint url = 'https://paramgaming.com/api/v1/user/signup' # Define the data to be submitted, assuming it's a dictionary form_data = { 'email': 'hjskdfkjshd@gmail.com', 'password': 'Example9222', 'referCode': '9E9DB2890A', # Add more fields as needed } # Define headers if needed headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'method': 'POST', 'Content-Type': 'application/json', 'Cookie': 'connect.sid=s%3ALwmqc4NrpJnt_f827oD-vNClyk2hJOA_.BX997BOyCtA1WNSm%2FHM8siFqSQAWjR7aHhm%2FT0YgqMQ; __cf_bm=vK7Md4y4kSfUD4OncFtpM4CvGPVHx7mMJAkMNx5xP5U-1713303566-1.0.1.1-p_RRTI2mVqw4Tx7M8HbZQwRPjdQsr1RlxtIqR02.dJIyA3avWPcLWQuNePG7zGnJmxWEg7TcSSi4BDIswd0q9A; cf_clearance=2cyDdSR.CeyW27jGNzeLf5CYBrWrwym8ldITE9fcgs0-1713303990-1.0.1.1-0a.GNYZyTCo4GVxrV2qUb2Hy1RyolgBVK_0RsG2hcs98v0_7inG_467QLtzyn2RLzvPXeUGg583L0._yCt58lQ', 'Accept': 'application/json, text/plain, */*', 'Referer': 'https://paramgaming.com/?referCode=9E9DB2890A', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept-Language': 'en-US,en;q=0.9', 'path': '/api/v1/user/signup', 'Origin': 'https://paramgaming.com', 'scheme': 'https' # Add more headers as needed } # Define the number of times to submit the form num_submissions = 1 # Loop to submit the form multiple times for _ in range(num_submissions): # Make the POST request response = requests.post(url, data=form_data, headers=headers) # Check if the request was successful (status code 200) if response.status_code == 200: print("Form submitted successfully!") else: print("Form submission failed with status code:", response.status_code)
修正数据格式与请求头不匹配问题:你设置了
Content-Type: application/json,但用data=form_data发送的是表单格式数据,接口会因格式不匹配拒绝请求。把data=form_data改成json=form_data,requests会自动将数据序列化为JSON格式,甚至可以删掉手动设置的Content-Type,工具会自动处理。移除无效请求头:headers里的
method、path、scheme不是HTTP标准请求头,属于冗余内容,可能被服务器判定为异常请求,直接删除这三个字段。更新Cookie值:Cookie中的
connect.sid、__cf_bm、cf_clearance都有有效期,尤其是Cloudflare的cf_clearance过期后会直接导致403。建议重新从浏览器开发者工具抓取最新的Cookie替换。使用完整的User-Agent:当前的User-Agent不完整,浏览器标准UA会包含更多信息,比如
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36,完整UA能降低被拦截的概率。
修改后的代码示例:
import requests url = 'https://paramgaming.com/api/v1/user/signup' form_data = { 'email': 'hjskdfkjshd@gmail.com', 'password': 'Example9222', 'referCode': '9E9DB2890A', } headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', 'Cookie': '这里替换成最新的Cookie值', 'Accept': 'application/json, text/plain, */*', 'Referer': 'https://paramgaming.com/?referCode=9E9DB2890A', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept-Language': 'en-US,en;q=0.9', 'Origin': 'https://paramgaming.com', } response = requests.post(url, json=form_data, headers=headers) if response.status_code == 200: print("注册成功!") else: print(f"注册失败,状态码:{response.status_code}") # 打印响应内容,查看服务器给出的具体错误信息 print("响应内容:", response.text)
另外,建议打印response.text查看服务器返回的具体错误提示,这能帮你更快定位问题,比如是否是验证码、IP限制或者字段缺失等原因。
内容的提问来源于stack exchange,提问作者Eddie

