-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatibility with Python 3 #115
Comments
Ran into this importing the linkedin module due to the older exception handling syntax. I see the
|
|
I get |
So, I could use this solution when I was running the import on a Jupyter Notebook (I'm trying to get the data for doing some analysis), but this doesn't help when using IPython in the Terminal. @harps116 I'm trying to execute the steps on the Quick usage, I have all the requirements installed, including Also, I saw that most of the issues are related to python3 compatibility or so. |
@luisberns you might want to try taking a look at this fork which looks like has some updates for Python 3 compatibility. https://github.com/HootsuiteLabs/python-linkedin-v2 Even that fork's setup.py lists the latest Python version as 3.4. So it's possible that it works on later versions, or it hasn't been tested with later versions, or they just forgot to update the setup.py, etc. But might as well try it! 😄 That said, even if you have all the requirements installed, if all the files in this library haven't been updated to work with Python 3, you run your code with Python 3, and your code imports one of those files that has Python 2-specific syntax, then the Python 3 interpreter will choke on when it encounters the Python 2-specific syntax. As for your jupyter notebook, it's possible that your jupyter notebook kernel is running python 2, but your IPython terminal is starting a Python 3 interpreter. I.e., when you installed jupyter, it's possible the Python 2 lib got installed into your Python 2's site-packages (if you have one). Your Python versions should be visible in the upper-right corner of the notebook under the logout button, and also at the top of your IPython prompt. I'm not sure this is the case for you but just throwing it out there as a possibility :) 🤷♂ |
@ramosjoel Thank you for the reply! I'm using Conda and my Python version is 3.6, I'm trying to rewrite the Now I'm able to run I'm attaching my # -*- coding: utf-8 -*-
import http.server
from urllib import parse
from .linkedin import LinkedInApplication, LinkedInAuthentication, PERMISSIONS
def quick_api(api_key, secret_key, port=8000):
"""
This method helps you get access to linkedin api quickly when using it
from the interpreter.
Notice that this method creates http server and wait for a request, so it
shouldn't be used in real production code - it's just an helper for debugging
The usage is basically:
api = quick_api(KEY, SECRET)
After you do that, it will print a URL to the screen which you must go in
and allow the access, after you do that, the method will return with the api
object.
"""
auth = LinkedInAuthentication(api_key, secret_key, 'http://localhost:8000/',
PERMISSIONS.enums.values())
app = LinkedInApplication(authentication=auth)
print(auth.authorization_url)
_wait_for_user_to_enter_browser(app, port)
return app
def _wait_for_user_to_enter_browser(app, port):
class MyHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
p = self.path.split('?')
if len(p) > 1:
params = parse.parse_qs(p[1], True, True)
app.authentication.authorization_code = params['code'][0]
app.authentication.get_access_token()
server_address = ('', port)
httpd = http.server.HTTPServer(server_address, MyHandler)
httpd.handle_request() |
Just an update, I'm now using the code from this PR #126 |
@luisberns the docstring on that function suggests that it will print an authorization url. Looking at the code you pasted, you can see that is the case.
From the docstring:
So I expect that once that authorization url is printed to your terminal (or notebook) you'll have to launch the browser yourself, navigate to the printed URL, and log in to authenticate yourself. Evidently this function waits for that to happen before it continues, and then returns an authenticated LinkedInApplication instance. That's at least how it looks to me. Hope this helps :) |
@ramosjoel Yes, got it! I could open by clicking the link, now I'm trying to get the request to work. First I had problems with the I'm trying to figure this out, if you have any suggestions, thank you for your help until now! |
@luisberns the For example, for the URL
Given that in my example,
If this is the case, you should have gotten the, This implies that your If I were you, I would run your code in a debugger and step through to inspect what the values are. Alternatively, if you run your program on the command line, you can pass python the |
Oh perfect, now I understand better how this function works, thanks. I managed to make the request or at least I'm not getting an error anymore, but I'm still getting a response One thing is that the Redirect URL without ending with a '.com' couldn't make the request, once I changed I was able to perform the request but got the error above. |
@luisberns this is how it looks to me:
This hides the response code from you which I think would be helpful to know, but judging by the error message that was printed for you, I would guess that you received a 401 response which would mean that your credentials are unauthorized. In fact, it looks like the author of the library grabs the status code of the response so that it can be looked up in a dictionary that maps bad status codes to custom exceptions so as to raise an exception that's specific to the error you received.
Thus, if you did receive a 401, you should have seen a |
Thank you @admhpr. This fixed my problem. 🥇 |
|
Putting it simply:
File "/usr/local/lib/python3.6/dist-packages/linkedin/server.py", line 24 print auth.authorization_url ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int auth.authorization_url)?
The text was updated successfully, but these errors were encountered: