发布时间:2019-09-22 08:06:11编辑:auto阅读(2743)
# -*- coding: utf-8 -*-
import requests
BASE_URL = 'https://api.github.com'
def construct_url(end_point):
return '/'.join([BASE_URL, end_point])
def basic_auth():
"""http基本认证"""
response = requests.get(construct_url('user'), auth=('5********', '**********'))
print response.text
print response.request.headers
basic_auth()
def basic_oauth():
headers = {'Authorization': 'token fafsffsfsfafasfasfasfsafafasf'}
response = requests.get(construct_url('user'), headers=headers)
print response.request.headers
print response.text
print response.status_code
from requests.auth import AuthBase
class GithubAuth(AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
#requests 加 headers
r.headers['Authorization'] = ''.join(['token', self.token])
return r
def oauth_advanced():
auth = GithubAuth('fafsffsfsfafasfasfasfsafafasf')
response = requests.get(construct_url('user'), auth=auth)
print response.text
oauth_advanced()
上一篇: python学习——POP3收取邮件
下一篇: python 静态变量
51383
50859
41447
38235
32737
29637
28450
23360
23294
21625
1719°
2450°
2044°
1978°
2333°
2010°
2719°
4553°
4359°
3109°