waditu / tushare

TuShare is a utility for crawling historical data of China stocks
BSD 3-Clause "New" or "Revised" License
12.86k stars 4.29k forks source link

ts.get_today_all()方法潜在的问题 #657

Open 824zzy opened 6 years ago

824zzy commented 6 years ago

源码中trading.py的_parsing_dayprice_json()函数内:

这句如果设定为10秒钟,并且网速不太快的话可能会超时,因此设定时间长一些

text = urlopen(request, timeout=10).read()    
=>
#设置为60秒就足够了
text = urlopen(request, timeout=60).read()
ppuserxu commented 6 years ago

这个问题,我没有遇到过。不过,是个提醒。谢谢楼主。

Jeff-Tian commented 5 years ago

我在连手机 4G 网时碰到这个问题了,不知道这个参数可以从外面调 ts.get_today_all() 时传进去吗?

重现:https://bitqbit.herokuapp.com/market

源码:https://github.com/fudan-mse/bitq

克隆到本地后,sh start-docker.sh 即可在本地运行,通过限制网速可以重现。

[Getting data:]#[2019-05-26 10:13:22,303] ERROR in app: Exception on /market [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/webapp/app.py", line 28, in market
    df = ts.get_today_all()
  File "/usr/local/lib/python3.7/site-packages/tushare/stock/trading.py", line 314, in get_today_all
    df = _parsing_dayprice_json('hs_a', 1)
  File "/usr/local/lib/python3.7/site-packages/tushare/stock/trading.py", line 116, in _parsing_dayprice_json
    text = urlopen(request, timeout=10).read()
  File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 456: