I have added one line ( import pdb; pdb.set_trace()
) to httplib's HTTPConnection.putheader, so I can see what's going on inside.
Python26\Lib\httplib.py
, line 489:
def putheader(self, header, value):
"""Send a request header line to the server.
For example: h.putheader('Accept', 'text/html')
"""
import pdb; pdb.set_trace()
if self.__state != _CS_REQ_STARTED:
raise CannotSendHeader()
str = '%s: %s' % (header, value)
self._output(str)
then ran this from the interpreter
import urllib2
urllib2.urlopen('http://www.ioerror.us/ip/headers')
... and as expected PDB kicks in:
> c:\python26\lib\httplib.py(858)putheader()
-> if self.__state != _CS_REQ_STARTED:
(Pdb)
in PDB I have the luxury of evaluating expressions on the fly, so I have tried to enter self.__state
:
(Pdb) self.__state
*** AttributeError: HTTPConnection instance has no attribute '__state'
Alas, there is no __state
of this instance. However when I enter step
, the debugger gets past the
if self.__state != _CS_REQ_STARTED:
line without a problem. Why is this happening? If the self.__state
doesn't exist python would have to raise an exception as it did when I entered the expression.
Python version: 2.6.4 on win32