在下面的代码中,我使用requests.post
.如果网站关闭,有什么可能继续?
我有以下代码:
def post_test():
import requests
url = 'http://example.com:8000/submit'
payload = {'data1': 1, 'data2': 2}
try:
r = requests.post(url, data=payload)
except:
return # if the requests.post fails (eg. the site is down) I want simly to return from the post_test(). Currenly it hangs up in the requests.post without raising an error.
if (r.text == 'stop'):
sys.exit() # I want to terminate the whole program if r.text = 'stop' - this works fine.
我怎么能提出这些要求呢.post超时,或者从post_test()返回(如果有).com或其/submit应用程序已关闭?