Python Webdriver raises http.client.BadStatusLine error

六眼飞鱼酱① 提交于 2020-01-07 02:16:12

问题


I'm writing a parser and I'm using Selenium Webdriver. So, I have this https://repl.it/Dgtp code and it's working fine until one random element and throws following exception: http.client.BadStatusLine: ''
Don't know how to fix it at all. Help.

[UPD]

I tried to scroll the page via webdriver (it had to cause thumbnails to load) and got this https://repl.it/DkiX error series. It would be caused by HTTP error from one of images which were loading, but I've not found any loading errors on the page. Still searching the answer.


回答1:


This is a urllib problem. This happens most commonly in python3. What it means is that the status code that the server returned isn't recognized by the http library. Sometimes the server doesn't receive the request at all and the status code returns an empty string triggering that error.

How to fix

Check if the URL string has a trailing newline character. Make sure that your URLs are stripped of any leading or trailing special characters. More info here

If everything looks fine with the URL just treat the exception

import http
try:
    browser.get(MONTHLY_URL)
except http.client.HTTPException as e:
    print e


来源:https://stackoverflow.com/questions/39681605/python-webdriver-raises-http-client-badstatusline-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!