尝试仅在python中使用requests/urllib请求url时发生重定向错误

尝试仅在python中使用requests/urllib请求url时发生重定向错误,python,django,redirect,curl,urllib,Python,Django,Redirect,Curl,Urllib,我正在尝试将数据发布到我服务器中的url。。。但我一直在向那个url(那个服务器上的任何url)发送任何请求,举个例子 http://apimy.in/page/test 该网站是用python3.4/django1.9编写的 我可以在php中使用curl发送请求,没有任何问题 但是python的任何请求都会导致某种重定向错误 首先,我尝试了请求lib 我犯了这个错误 TooManyRedirects at /api/sender Exceeded 30 redirects. Request

我正在尝试将数据发布到我服务器中的url。。。但我一直在向那个url(那个服务器上的任何url)发送任何请求,举个例子

http://apimy.in/page/test
该网站是用python3.4/django1.9编写的

我可以在
php
中使用
curl
发送请求,没有任何问题

但是python的任何请求都会导致某种重定向错误

首先,我尝试了
请求
lib

我犯了这个错误

TooManyRedirects at /api/sender
Exceeded 30 redirects.
Request Method: GET
Request URL: http://localhost:8000/api/sender
Django Version: 1.9.6
Exception Type: TooManyRedirects
Exception Value:

Exceeded 30 redirects.
我认为
请求可能有问题,所以我尝试了
urllib

request_data = urllib.parse.urlencode({"DATA": 'aaa'}).encode()
response = urllib.request.urlopen("http://apimy.in/page/test" , data=request_data)



HTTPError at /api/sender
HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Found
Request Method: GET
Request URL:    http://localhost:8000/api/sender
Django Version: 1.9.6
Exception Type: HTTPError
Exception Value:    
HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Found
Exception Location: c:\Python344\lib\urllib\request.py in http_error_302, line 675
im使用mod_wsgi和apache为网站提供服务

因为您正在使用该模块,您是否尝试告诉请求模块忽略重定向

import requests
response = requests.get('your_url_here', allow_redirects=False)
也许这是工作。 如果这不起作用,您还可以尝试更改
用户代理
,以防出于安全原因服务器配置为删除
脚本请求

import requests
headers = {'user-agent': 'some_user_agent'}
response = requests.get(url, headers=headers)
由于您正在使用该模块,您是否尝试告诉请求模块忽略重定向

import requests
response = requests.get('your_url_here', allow_redirects=False)
也许这是工作。 如果这不起作用,您还可以尝试更改
用户代理
,以防出于安全原因服务器配置为删除
脚本请求

import requests
headers = {'user-agent': 'some_user_agent'}
response = requests.get(url, headers=headers)

thanx,如果文档已移动,则禁用重定向
错误…但是通过设置用户代理,我使其工作thanx,如果文档已移动,则禁用重定向错误…但是通过设置用户代理,我使其工作thanx