A Python beginner tries to get a Qiita.com authentication token.
#!C:/Python27/
# -*- coding:utf-8 -*-
import urllib
import urllib2
import cookielib
import json
# http is urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=1), urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
urllib2.install_opener(opener)
def get_token() :
name = 'user_name'
passwd = '**********'
url = 'https://qiita.com/api/v1/auth'
login_post = {'url_name':name,'password':passwd}
param = urllib.urlencode(login_post)
req = urllib2.Request(url,param)
res = urllib2.urlopen(req)
token = json.loads(res.read())
return token['token']
'
Recommended Posts