Quack Space Marine
Quack Space Marine

Reputation: 55

"local variable 'e' referenced before assignment" what does this error mean? How do I fix this error?

I'm trying use del.icio.us API and following the examples from the book Programming Collective Intelligence

When I use these commands in python 3.6.2:

>>> from deliciousrec import *

>>> delusers=initializeUserDict('programming')

I get this error:

<urlopen error [Errno 11001] getaddrinfo failed>, 4 tries left.  
<urlopen error [Errno 11001] getaddrinfo failed>, 3 tries left.  
<urlopen error [Errno 11001] getaddrinfo failed>, 2 tries left. 
<urlopen error [Errno 11001] getaddrinfo failed>, 1 tries left.  
Traceback (most recent call last):               
   File "<stdin>", line 1, in <module> 
   File"C:\Users\user\AppData\Local\Programs\Python\Python36\deliciousrec.py", line 10, in initializeUserDict            
     for p1 in get_popular(tag=tag)[0:count]:   
   File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pydelicious-0.6-py3.6.egg\pydelicious\__init__.py", line 1042, in get_popular        
   File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pydelicious-0.6-py3.6.egg\pydelicious\__init__.py", line 1026, in getrss    
   File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pydelicious-0.6-py3.6.egg\pydelicious\__init__.py", line 455, in dlcs_rss_request      
   File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pydelicious-0.6-py3.6.egg\pydelicious\__init__.py", line 239, in http_request                    
   UnboundLocalError: local variable 'e' referenced before assignment   

I can not open pydelicious-0.6-py3.6.egg and access the init file that is asked to be modified here. Has anyone seen this type of error before. How do I solve it?

Upvotes: 1

Views: 1896

Answers (1)

abarnert
abarnert

Reputation: 365925

This library's PyPI page is written in the past tense:

Was a complete Python interface to del.icio.us Bookmarks’ HTTP API’s.

Its home page is a Github repo that says:

Old pydelicious work (--2010)

The only update since 2010 is:

[2016] del.icio.us was gone since about 2009, and redirected to delicious.com. At the moment there is another login page back at del.icio.us. Not sure what they're up to now."

Even the old 2010 page said:

IMPORTANT: pydelicious has not been updated to use the OAuth protocol. New users with a Yahoo account/email will not be able to use this library.

So, it seems very likely that this library was never updated for Python 3.x, or for up-to-date versions of whichever libraries it depends on, or for whatever the new del.icio.us is.


But meanwhile, if you want to debug it yourself, you can.

To look at source inside a .egg archive, you can either do it from within Python:

>>> import deliciousrec
>>> import inspect
>>> inspect.getsource(deliciousrec)

… or you can extract the .egg archive using your favorite ZIP-file tool, because that's all .egg files are.

… or you can just clone the GitHub repo, or view it online, which is probably the best solution.


As Hamms pointed out in a comment, if you look at the function that's raising, it's doing this:

except urllib2.HTTPError, e:
    # reraise unexpected protocol errors as PyDeliciousException
    raise PyDeliciousException, "%s" % e

In Python 2, that meant to handle exceptions of type urllib2.HTTPError, and bind e to the exception for the rest of the function.

In Python 2.6, this was soft-deprecated in favor of this new syntax:

except urllib2.HTTPError as e:
    # reraise unexpected protocol errors as PyDeliciousException
    raise PyDeliciousException, "%s" % e

In Python 3, the old syntax went away entirely, so it's now illegal.

The 2to3 tool will automatically fix this particular issue for you, but it may not fix everything; you'll need to manually port the code to 3.x. And of course that may not do any good, since you're trying to call an API that went away in 2010.

Upvotes: 4

Related Questions