๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ปTech/๐Ÿpython

[Python] httplib.badstatusline ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

by _viper_ 2019. 11. 1.
๋ฐ˜์‘ํ˜•

httplib๋กœ API URI ํ˜ธ์ถœํ•˜๋Š” ๊ณผ์ •์—์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

API ํ˜ธ์ถœ์„ ๋ฐ˜๋ณตํ•˜์—ฌ ๊ณ„์† ํ˜ธ์ถœํ•˜๋Š” ์ฝ”๋“œ์˜€๋Š”๋ฐ,

์ฒซ๋ฒˆ์งธ ํ˜ธ์ถœ์€ ์ •์ƒ์ ์œผ๋กœ ํ˜ธ์ถœ ๋˜์ง€๋งŒ ๋‘๋ฒˆ์งธ ํ˜ธ์ถœ๋ถ€ํ„ฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋„ค์š”

Traceback (most recent call last): 
  File "test.py", line 40, in  
    clusterInfo = getAppPendingCnt(conn) 
  File "yarnAppStatus.py", line 9, in getAppPendingCnt 
    r1 = conn.getresponse() 
  File "/usr/lib64/python2.7/httplib.py", line 1113, in getresponse 
    response.begin() 
  File "/usr/lib64/python2.7/httplib.py", line 444, in begin 
    version, status, reason = self._read_status() 
  File "/usr/lib64/python2.7/httplib.py", line 408, in _read_status 
    raise BadStatusLine(line) 
httplib.BadStatusLine: '' 

 

๐Ÿšซ ๋ฌธ์ œ ์ฝ”๋“œ

  • ์›์ธ: connection์„ ๋Š์ง€ ์•Š๊ณ  ์žฌํ˜ธ์ถœํ•ด์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ
  • ์กฐ์น˜๋ฐฉ๋ฒ•: connection close > retry connection > api call
conn = httplib.HTTPConnection('host','port')

while 1:
	callApi(conn)

 

๐Ÿ’ก ์ˆ˜์ • ์ฝ”๋“œ

while 1:
	conn = httplib.HTTPConnection('host','port')
	callApi(conn)
	conn.close()