初来乍到,请教一个 bug 。。。 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
hqtc

初来乍到,请教一个 bug 。。。

  •  
  •   hqtc May 6, 2016 7164 views
    This topic created in 3646 days ago, the information mentioned may be changed or developed.
    import urllib.request urllib.request.urlopen("http://hq.sinajs.cn/list=sh000001").read() 

    python 版本 3.4.

    在 windows 下正常。 但是在阿里云服务器上抛出如下异常。。 在阿里云上换上百度的 url 也可以读出,敢问是怎么回事。。。

    Traceback (most recent call last): File "/usr/lib/python3.4/urllib/request.py", line 1232, in do_open h.request(req.get_method(), req.selector, req.data, headers) File "/usr/lib/python3.4/http/client.py", line 1065, in request self._send_request(method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1103, in _send_request self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1061, in endheaders self._send_output(message_body) File "/usr/lib/python3.4/http/client.py", line 906, in _send_output self.send(msg) File "/usr/lib/python3.4/http/client.py", line 841, in send self.connect() File "/usr/lib/python3.4/http/client.py", line 819, in connect self.timeout, self.source_address) File "/usr/lib/python3.4/socket.py", line 509, in create_connection raise err File "/usr/lib/python3.4/socket.py", line 500, in create_connection sock.connect(sa) TimeoutError: [Errno 110] Connection timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "price_and_deal_data.py", line 33, in <module> data_arr = urllib.request.urlopen(url).read().decode("gbk").split("=")[1].split(",") File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.4/urllib/request.py", line 455, in open respOnse= self._open(req, data) File "/usr/lib/python3.4/urllib/request.py", line 473, in _open '_open', req) File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain result = func(*args) File "/usr/lib/python3.4/urllib/request.py", line 1258, in http_open return self.do_open( http.client.HTTPConnection, req) File "/usr/lib/python3.4/urllib/request.py", line 1235, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 110] Connection timed out> 
    9 replies    2016-05-07 14:36:33 +08:00
    hging
        1
    hging  
       May 6, 2016   1
    我猜是爬太多 新浪封了...
    clockwerk
        2
    clockwerk  
       May 6, 2016
    目测编码问题,去掉 decode 试试
    ldsink
        3
    ldsink  
       May 6, 2016
    Connection timed out 错误,这是连接超时。阿里云连你要下载的那个网址有问题。

    PS :别用 urllib ,太麻烦了,用 requests ,这都快成准标准库了, HTTP for Humans 。
    tongle
      &nsp; 4
    tongle  
       May 6, 2016   1
    确定下你的服务器是否能访问 URL
    star001007
        5
    star001007  
       May 6, 2016
    抓我浪接口做甚
    thomasjiao
        6
    thomasjiao  
       May 6, 2016
    加个 referer 和 ua 之类的试试吧,这种接口据内部人士说能抗 1000w 的并发
    cxbig
        7
    cxbig  
       May 6, 2016   1
    在服务器上用 curl 或 wget 试试能不能读到页面,就可以知道是你程序问题还是服务器连接问题。
    hqtc
        8
    hqtc  
    OP
       May 6, 2016
    感谢各位大大,我刚用 wget 试了一下,确实我的服务器不能访问这个 url 了。。我也就每天下午 5 点抓一下三大股指的点数数据,这样也会被封么?真是醉了。。。

    有没有什么解决方案?
    xiahei
        9
    xiahei  
       May 7, 2016
    A sorrowful story !
    About   &nbp; Help     Advertise     Blog     API     FAQ     Solana     2610 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 50ms UTC 12:18 PVG 20:18 LAX 05:18 JFK 08:18
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86