Django: [Errno 10054] An existing connection was forcibly closed by the remote host. When using urllib2 and httplib2
def scrape(request):
url = request.GET.get('url')
conn = httplib2.Http()
resp, content = conn.request(uri=url)
return HttpResponseRedirect(content)
def scrape1(request):
url = request.GET.get('url')
req = urllib2.Request(url, headers={ 'User-Agent': 'Magic Browser' })
con = urllib2.urlopen(req)
When I use any of these functions using this url, http://gizmodo.com/5980796/first%20ever-incredible-footage-of-a-thought-being-formed , I get the following error message:
[Errno 10054] An existing connection was forcibly closed by the remote host
This happens when I run this function in a view in my Django app. However, if I run these commands in the python shell, I don't get an error and the url is retrieved successfully. Please help me understand what I am doing wrong and how I can fix it so I don't get this error anymore. Thank.
+3
source to share
No one has answered this question yet
Check out similar questions: