【发布时间】:2018-08-31 19:33:18
【问题描述】:
我使用来自这里的代码https://github.com/ozgur/python-linkedin 以及我的 ID 和密钥。如果我运行此代码并转到 localhost:8080(我使用了此端口),我会收到以下异常:
127.0.0.1 - - [31/Aug/2018 13:25:49] "GET / HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 65176)
Traceback (most recent call last):
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\http\server.py", line 646, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 717, in __init__
self.handle()
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\http\server.py", line 426, in handle
self.handle_one_request()
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\http\server.py", line 414, in handle_one_request
method()
File "C:/Users/osads/PycharmProjects/python-linkedin-master/examples/http_api.py", line 60, in do_GET
open_new_tab(liw.authentication.authorization_url)
File "C:\Users\osads\PycharmProjects\python-linkedin-master\linkedin\linkedin.py", line 101, in authorization_url
qsl = ['%s=%s' % (quote(k), quote(v)) for k, v in qd.items()]
File "C:\Users\osads\PycharmProjects\python-linkedin-master\linkedin\linkedin.py", line 101, in <listcomp>
qsl = ['%s=%s' % (quote(k), quote(v)) for k, v in qd.items()]
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\urllib\parse.py", line 791, in quote
return quote_from_bytes(string, safe)
File "C:\Users\osads\AppData\Local\Programs\Python\Python37-32\lib\urllib\parse.py", line 816, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
如何解决这个问题?
UPD:来自linkedin.py的代码
@property
def authorization_url(self):
qd = {'response_type': 'code',
'client_id': self.key,
'scope': (' '.join(self.permissions)).strip(),
'state': self.state or self._make_new_state(),
'redirect_uri': self.redirect_uri}
# urlencode uses quote_plus when encoding the query string so,
# we ought to be encoding the qs by on our own.
qsl = ['%s=%s' % (quote(k), quote(v)) for k, v in qd.items()]
return '%s?%s' % (self.AUTHORIZATION_URL, '&'.join(qsl))
【问题讨论】:
-
你只是在使用 python-linkedin 的例子吗?可能值得发布示例的相关部分,以便我们了解发生了什么。但是你能看一下linkedin.py 的行,看看它在做什么,以及那个时候的坏值是什么?
-
是的,我使用示例和我所做的所有更改输入我的号码和密钥并选择另一个端口: PORT = 8080 LINKEDIN_API_KEY = '' # 我的密钥 LINKEDIN_API_SECRET = '' # 我的秘密。 linkedin.py 代码添加到问题
标签: python oauth-2.0 linkedin-api