get status_code for http.urlopen



如何打印此响应的状态码?(如200/401等)

resp = http.urlopen('POST', 'https://api.bitbucket.org/2.0/repositories/6789oh', headers=headers, body=json.dumps(data))
print(str(resp.data))

我试着:

resp.code
resp.get_code()

等,但没有一个适用于http.urlopen

我会使用urllib。请求,试试这个,看看是否有帮助

进口urllib。请求,json

试题:

resp=urllib.request.urlopen('POST','https://api.bitbucket.org/2.0/repositories/6789oh',headers=headers, body=json.dump(data))

除了urllib.error.URLError:

print(str(a.status) +"n" + str(a.message))

except urllib.error.URLError:

print(str(e.code) +"n"+ str(e.msg))

最新更新