Q:

How to raise HTTPError

To test some code which uses urllib2, I want to raise an HTTPError to make sure it is handled correctly.
HTTPError has a constructor:
def __init__(self, url, code, msg, hdrs, fp):

I don't know what to pass as the last argument fp.
Can you help me with an example that will raise an HTTPError e.g. 
raise HTTPError('arg1','arg2','arg3','arg4',...
How can it be done?

A:

Pass fp=None.
From the source code:

# The addinfourl classes depend on fp being a valid file
# object.  In some cases, the HTTPError may not have a valid
# file object.  If this happens, the simplest workaround is to
# not initialize the base classes.
if fp is not None:
    self.__super_init(fp, hdrs, url, code)

fp needs to be a file-like object, so you could pass a StringIO object if you liked.

