Error importing facebook module in Python

I installed facebook-sdk using the command below:

pip install facebook-sdk 

But when importing, I ran into a problem:

 import facebook Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python33\lib\site-packages\facebook.py", line 222 except urllib2.HTTPError, e: ^ SyntaxError: invalid syntax 

How can i fix this?

+6
source share
3 answers

This is the old syntax for throwing exceptions. It should be replaced with the as keyword with Python 2.6 and is probably not supported at all in Python 3.

Try to find another library that supports Python 3, or consider downgrading to Python 2.6 (which should really be the last option).

You can view all the details on PEP 3110 .

+4
source

Check out this version: https://github.com/pythonforfacebook/facebook-sdk/tree/b9b0de30402bb99387f35630446b5446a288d14b

Download it and install using:

 python setup.py install. 

This works for me:

 $ pip freeze --local facebook-sdk==1.0.0a0 

:)

+4
source

According to the documentation, the Facebook-SDK will not work with Python3.4 if you use this version: https://facebook-sdk.readthedocs.org/en/latest/install.html

+3
source

All Articles