我return json_run(url, data)
在线上遇到语法错误,我不知道为什么。
from urllib.request import urlopen
from json import loads as json_loads
import time
from urllib.error import HTTPError
import random
def json_run(url, data) :
s = url + data
try:
r = urlopen(s)
o = json_loads(r.read().decode('utf8'))
return o
except HTTPError as err:
if err == 504:
# Retry
time.sleep(random.randint(1, 10)
return json_run(url, data)
else:
raise