python


Unable to handle “HTTP Badstatus line” exception


I want to handle http.client.BadStatusLine: '' exception.
I am on python3. My code is
import http.client
try:
req = urllib.request.Request(url, headers={'User-Agent': 'Chrome/51'})
html = urllib.request.urlopen(req).read()
soup = BeautifulSoup(html,"html.parser")
return soup
except http.client.HTTPException as eror:
print("Boom")
but httpException is not in python3?
I read stackOverFloeQuestion and this but unable to catch it. Any help?
You need to make up your mind :-). You can either use http.client or urllib.request, but you should not use one and then try to catch errors from the other. If you want to stick with urllib.request, the class to catch is urllib.error.HTTPError.
Perhaps it may be more opportune in your case to use Requests, which is a higher level http library.

Related Links

Copy selected lines of text from one file to another with command line argument with or without spaces
TypeError: can't use a string pattern on a bytes-like object
Why does my code skip to the end and ignore parts of my code?
Matplotlib scroll_event not working with GTK3Agg backend
SELECT conditions on relations with SQLAlchemy
longest and shortest curves selected
Get the key with the maximum nested key in a python dictionary
Python fermat program only works for low numbers
How to create list of all parts of elements in NumPy array (Python list)
Encoding issue for Python tool Unidecode on CL
Accept only numbers on a python string [closed]
scrapy spider pass parameters
sending data to particular client from twisted server
Type Error, object cannot be interpreted as an index with tk message box bind commands
What is this condition testing? [duplicate]
Testing Flask login and authentication?

Categories

HOME
ajax
websphere
paramiko
recyclerview
iis-7.5
avl-tree
constructor
octopus-deploy
game-physics
simple-injector
cratedb
spring-cloud-config
cross-platform
mule-studio
quartus
anychart
eclipselink
attask
ip-camera
koa
richfaces
yosys
fabric
tampermonkey
sumo
switching
rhmap
mef2
metadata-extractor
classpath
pentaho-report-designer
pcre
bxslider
sharp
cell-array
jboss5.x
ioc-container
receipt
pycparser
discord.net
meta-raspberrypi
fax
onbackpressed
exiftool
median
powermta
jdbi
upsert
lirc
fqdn
tuleap
greenhills
crash-reports
fedora20
tofixed
search-box
redux-router
autoresize
iron.io
rsqlite
sql-import-wizard
coremidi
backstop.js
picking
inet
group-concat
fill
drf-nested-routers
self-hosting
affix
android-snackbar
visual-studio-code
castle-windsor-3
scrollspy
google-plus-one
multipleselection
line-numbers
ultrawingrid
colt
help-viewer
opensocial
cling
gamepad
grunt-contrib-compass
client-library
fluidsynth
bulbs
tfs-power-tools
ninject-extensions
jpf
objectbrowser
opengl-es-lighting
rubycas
clause
asp.net-routing
web-statistics

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App