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

使用requests.post提交URL遇405错误,求助向目标站点发送链接

Fixing 405 Method Not Allowed When Posting to the Message Board

First, let's unpack the 405 error: it means the server at http://csec380-core.csec.rit.edu:5004/ rejects the POST method for the root URL you're targeting. This usually happens for one of a few simple reasons—let's break down how to fix it:

Step 1: Inspect the Message Board's Form Details

To get the right request parameters, use your browser's developer tools to check the actual form on the page:

  1. Visit http://csec380-core.csec.rit.edu:5004/ in your browser.
  2. Press F12 to open DevTools, then navigate to the Elements tab.
  3. Locate the <form> element on the page and note three key details:
    • action: The specific URL the form submits to (it might be something like /submit instead of the root /).
    • method: Whether the form uses POST or GET—this is the HTTP method you need to mirror in your code.
    • The name attribute of the message input/textarea (you used message, but it could be msg, content, or another label).

Step 2: Adjust Your Python Code

Based on what you found in DevTools, update your code to match the form's requirements. Here are common scenarios:

Scenario 1: Form submits to a dedicated endpoint

If the form's action points to something like /submit, update your request URL:

import requests

# Use the correct endpoint from the form's action attribute
url = 'http://csec380-core.csec.rit.edu:5004/submit'
# Use the exact field name from the form's input
data = {'message': 'http://52.14.44.145/'}

r = requests.post(url, data=data)
print(r.status_code)
print(r.text)

Scenario 2: Form uses GET instead of POST

If the form's method is set to GET, switch to a GET request and pass your message as URL parameters:

import requests

url = 'http://csec380-core.csec.rit.edu:5004/'
params = {'message': 'http://52.14.44.145/'}

r = requests.get(url, params=params)
print(r.status_code)
print(r.text)

Scenario 3: Add Browser-like Headers (If Needed)

Some servers block requests that don't mimic a real browser. Add a User-Agent header to your request:

import requests

url = 'http://csec380-core.csec.rit.edu:5004/submit'
data = {'message': 'http://52.14.44.145/'}
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}

r = requests.post(url, data=data, headers=headers)
print(r.status_code)
print(r.text)

Quick Troubleshooting Tip

If you still hit errors, double-check for hidden input fields in the form (DevTools will show these)—some sites require a CSRF token or other hidden values to process submissions.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:16:33