2016-09-24 32 views
1

我尝试将数据发布到我的服务器的URL ...但停留在发送该URL(该服务器上的任何URL)的任何请求我在这里是一个例如重定向错误/ urllib的只有蟒蛇

http://apimy.in/page/test 

的网站是写在python3.4/django1.9

我可以phpcurl发送的请求没有任何问题

但与Python将导致对任何要求某种重定向错误

起初,我已经试过requests LIB

我得到了使用mod_wsgi的和Apache这个错误

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. 

我想也许有毛病requests所以我尝试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为网站服务

回答

0

由于您正在使用requests模块,您是否尝试告诉请求模块忽略重定向?

import requests 
response = requests.get('your_url_here', allow_redirects=False) 

也许这项工作。 如果这也不行,你也可以尝试改变你user-agent的情况下,您的服务器配置为下降script-requests出于安全原因。

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

thanx,通过禁用重定向如果得到'该文件已移动错误...但通过设置用户agen我得到了它的工作thanx – hretic