|
35 | 35 |
|
36 | 36 | try:
|
37 | 37 | # python 3
|
38 |
| - from urllib.parse import urlparse, urlunparse, urlencode |
| 38 | + from urllib.parse import urlparse, urlunparse, urlencode, quote_plus |
39 | 39 | from urllib.request import urlopen
|
40 | 40 | from urllib.request import __version__ as urllib_version
|
41 | 41 | except ImportError:
|
42 | 42 | from urlparse import urlparse, urlunparse
|
43 | 43 | from urllib2 import urlopen
|
44 |
| - from urllib import urlencode |
| 44 | + from urllib import urlencode, quote_plus |
45 | 45 | from urllib import __version__ as urllib_version
|
46 | 46 |
|
47 | 47 | from twitter import (
|
@@ -288,17 +288,15 @@ def GetAppOnlyAuthToken(self, consumer_key, consumer_secret):
|
288 | 288 | """
|
289 | 289 | Generate a Bearer Token from consumer_key and consumer_secret
|
290 | 290 | """
|
291 |
| - from urllib import quote_plus |
292 |
| - import base64 |
293 |
| - |
294 | 291 | key = quote_plus(consumer_key)
|
295 | 292 | secret = quote_plus(consumer_secret)
|
296 |
| - bearer_token = base64.b64encode('{}:{}'.format(key, secret)) |
| 293 | + bearer_token = base64.b64encode('{}:{}'.format(key, secret).encode('utf8')) |
297 | 294 |
|
298 | 295 | post_headers = {
|
299 |
| - 'Authorization': 'Basic ' + bearer_token, |
| 296 | + 'Authorization': 'Basic {0}'.format(bearer_token.decode('utf8')), |
300 | 297 | 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
301 | 298 | }
|
| 299 | + |
302 | 300 | res = requests.post(url='https://api.twitter.com/oauth2/token',
|
303 | 301 | data={'grant_type': 'client_credentials'},
|
304 | 302 | headers=post_headers)
|
|
0 commit comments