“Sesi permintaan di Python” Kode Jawaban

Permintaan Sesi

s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'x-test': 'true'})

# both 'x-test' and 'x-test2' are sent
s.get('https://httpbin.org/headers', headers={'x-test2': 'true'})
Nyn

Sesi permintaan di Python

import requests
 
session = requests.Session()
 
url = 'https://httpbin.org/headers'
 
access_token = {
    'Authorization': 'Bearer {access_token}'
    }
 
session.headers.update(access_token)
 
response1 = session.get(url)
response2 = session.get(url)
 
print('response1: ', response1.json()['headers']['Authorization'])
print('response2: ', response2.json()['headers']['Authorization'])
Outrageous Ostrich

Permintaan Sesi

s = requests.Session()

s.get('https://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get('https://httpbin.org/cookies')

print(r.text)
# '{"cookies": {"sessioncookie": "123456789"}}'
Nyn

Jawaban yang mirip dengan “Sesi permintaan di Python”

Pertanyaan yang mirip dengan “Sesi permintaan di Python”

Lebih banyak jawaban terkait untuk “Sesi permintaan di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya