0

I'm sending an HTTP request using Python 3's urllib and am receiving a bad status line exception.

Code:

mote_file = six.moves.urllib.request.urlopen(scan_uri)

Error message:

requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('\x00\x06\x87\x1aHTTP/1.0 200 Ok\r\n',))

The request was made successfully but I am getting an exception because of the special characters. Does anyone have any ideas on how to fix this or suppress the exception?

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • You might want to look at https://stackoverflow.com/questions/16138232/is-it-a-good-practice-to-use-try-except-else-in-python to see how to handle an exception in Python. For your code, the python doc for urlopen will lead you to the specific exception to handle. – tpgould Feb 01 '20 at 02:28

1 Answers1

0

I figured it out for my scenario.

In C:\Python36\lib\http\client.py, I added

if not line.startswith("HTTP/"): line = line[4:]

before

try: version, status, reason = line.split(None, 2)

in _read_status(self) function.

It removes the four characters before checking if the status is a valid one.