简体   繁体   English

Python HTTP错误500

[英]Python HTTP Error 500

I have this python code which gets data from this site. 我有此python代码,可从该站点获取数据。 When Thread(for function, not class) is being used it shows HTTP Error 500, other wise when its not being used it shows normally. 当使用Thread(用于函数,而不是类)时,它显示HTTP错误500;否则,在不使用Thread时,它正常显示。 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 您可以像这样捕获并读取Http error的内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM