I have this python code which gets data from this site. When Thread(for function, not class) is being used it shows HTTP Error 500, other wise when its not being used it shows normally. It's not the whole, just few snippets
from urllib2 import urlopen, Request
def getData(self):
dataRequest = Request('http://google.com')
dataResponse = urlopen(dataRequest)
dataData = dataResponse.read()
jsonData = loads(dataData)
...
Any help is appreciated! Thank you
You can catch and read the contents of the Http error
like
from urllib2 import urlopen, Request
def getData(self):
try:
dataRequest = Request('http://google.com')
dataResponse = urlopen(dataRequest)
dataData = dataRespons
jsonData = loads(dataData)
except urllib2.HTTPError, error:
contents = error.read()
print contents
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.