2014-07-21 184 views
1

我已經看到了幾個相關的帖子處理掛起請求使用超時參數,但我不確定如何診斷我的請求是掛起還是存在一些其他潛在問題。我正在傳輸一些數據並將其記錄下來並將其打印到控制檯。有兩次,現在我所看到的擴展在沒有數據打印到控制檯時期,當我interupt執行我得到以下堆棧跟蹤診斷掛起請求與請求

File "/home/matthew/Dropbox/pylibs/oandapy/oandapy.py", line 276, in start 
    for line in response.iter_lines(90): 
    File "/home/matthew/anaconda/lib/python2.7/site-packages/requests/models.py", line 663, in iter_lines 
    for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode): 
    File "/home/matthew/anaconda/lib/python2.7/site-packages/requests/models.py", line 627, in generate 
    for chunk in self.raw.stream(chunk_size, decode_content=True): 
    File "/home/matthew/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 240, in stream 
    data = self.read(amt=amt, decode_content=decode_content) 
    File "/home/matthew/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/response.py", line 187, in read 
    data = self._fp.read(amt) 
    File "/home/matthew/anaconda/lib/python2.7/httplib.py", line 543, in read 
    return self._read_chunked(amt) 
    File "/home/matthew/anaconda/lib/python2.7/httplib.py", line 585, in _read_chunked 
    line = self.fp.readline(_MAXLINE + 1) 
    File "/home/matthew/anaconda/lib/python2.7/socket.py", line 476, in readline 
    data = self._sock.recv(self._rbufsize) 
    File "/home/matthew/anaconda/lib/python2.7/ssl.py", line 246, in recv 
    return self.read(buflen) 
    File "/home/matthew/anaconda/lib/python2.7/ssl.py", line 165, in read 
    return self._sslobj.read(len) 

有一些額外的參數,我可以設置或地方登錄與連接的更多信息,從堆棧跟蹤中我不清楚問題是什麼。

+0

你有沒有找到更多關於此? – Halfgaar

+0

從我的回憶中,這個問題是間歇性的,我從來沒有深究到底是什麼導致了它 – mgilbert

回答

1

您可以爲HTTP會話超時設置,當您創建請求對象或發送的請求;請參閱here

timeout - (可選)在 秒內描述請求超時的浮點數。

但是,在傳輸過程中它看起來有點問題。出於測試目的,您可以通過chunk_size = 1iter_lines,並立即打印結果。有可能服務器不會發送HTTP分塊終結符\ r \ n(檢查您是否有自己的服務器?值得通過https嘗試其他服務器)。