2016-09-24 21 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