How to solve ConnectionError?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-12 09:19:47
0
1
913

Using the requests module in Python to capture data, the data I want can appear, but the data is incomplete. A ConnectionError will appear later. How can I solve it? I have set Timeout.

My code is as follows:

from pprint import pprint
import requests
import json

dict_num = dict()
for num in range(1,1771):
    url_api = "http://api.jisuapi.com/bencao/detail?appkey=bdc8ee0bb0227112&detailid={n}&isdetailed={n}".format(n=num)
    r = requests.get (url_api,timeout=60)
    data = r.json()
    pprint (data)
    detail2 = data
    pprint (detail2)
with open ("bencao_detail2", mode="w", encoding="utf8") as file:
    json.dump(detail2, file)
女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(1)
我想大声告诉你

There is nothing you can do if the other party's server fails, but you can try catch to catch the exception and try again after a while

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!