I am trying to make http requests to a server and examine the content I get back. However, when I try poking around the HTTPResponse object
with ipdb
, I keep getting *** Oldest frame
and I cant run any of the functions on the object that I should be able to run. Here is the block of code doing to fetching, and the ipdb
output:
code block:
for acc in sp_lost:
url = 'http://www.uniprot.org/uniprot/?query=mnemonic%3a'+acc+'+active%3ayes&format=tab&columns=entry%20name'
u = urllib.request.urlopen(url)
ipdb.set_trace()
ipdb output:
ipdb> url
'http://www.uniprot.org/uniprot/?query=mnemonic%3aSPATL_MOUSE+active%3ayes&format=tab&columns=entry%20name'
ipdb> u
*** Oldest frame
ipdb> str(u)
'<http.client.HTTPResponse object at 0xe58e2d0>'
ipdb> type(u)
<class 'http.client.HTTPResponse'>
ipdb> u.url
*** Oldest frame
ipdb> u.url() # <-- unable to run url() on object...?
*** Oldest frame
ipdb>
What does the *** Oldest frame
mean, and how can I get this object into something more useful that I can run the appropriate functions on?
u
is the PDB command to traverse stack frames. You are in the 'uppermost' frame already. help u
will tell you more about it:
u(p) Move the current frame one level up in the stack trace (to an older frame).
The command is closely related to d(own)
and w(here)
:
d(own) Move the current frame one level down in the stack trace (to a newer frame). w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the "current frame", which determines the context of most commands. 'bt' is an alias for this command.
If you want to print the variable u
, prefix it with a !
to have it not interpreted by the debugger as a debug command:
!u
!u.url
or use print()
:
print(u)
From the help pdb
output:
Commands that the debugger doesn't recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point ('!').
Oldest frame
is the frame in the stack where your program started; it is the oldest in time; the Newest frame
, the other end of the stack, is where Python is executing code and is the current frame of execution, where Python would continue if you hit the c(ontinue)
command.
A little demo with a recursive function:
>>> def foo():
... foo()
...
>>> import pdb
>>> pdb.run('foo()')
> <string>(1)<module>()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) w
/Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
<string>(1)<module>()
<stdin>(2)foo()
<stdin>(2)foo()
> <stdin>(1)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <string>(1)<module>()
(Pdb) u
> /Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
(Pdb) u
*** Oldest frame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With