Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

How to remove built-in headers of aiohttp.ClientSession()?

I'm trying to recreate my Zom record patch fucntion with aiohttp. What i have now:

    async def update_zoom_record(id, fields, token):
    url = urljoin(settings.GET_MEETING_URL, str(id))
    post_headers = {'origin': origin, 'Authorization': token,
                    'Content-Type': 'application/json'}    
    body = json.dumps({'topic': fields['subject']})   
    async with aiohttp.ClientSession() as session:            
            async with session.patch(url, json=body, headers=post_headers ) as resp:
               if resp.status != 204:
                    raise Exception('Problems with patching zoom meeting data')

And unlike simple resp = requests.get(url, headers=post_headers) it gives me status 400.

I've compared headers objects of both requests: async:

headers=<CIMultiDictProxy('Host': 'api.zoom.us', 'origin': 'https://developer.zoom.us',
'Authorization': 'Bearer ...', 
'Content-Type': 'application/json', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 
'User-Agent': 'Python/3.8 aiohttp/3.7.3', 'Content-Length': '30')>, real_url=URL('https://api.zoom.us/v2/meetings/876...'))

sync:

headers:{'User-Agent': 'python-requests/2.24.0', 'Accept-Encoding': 'gzip, deflate', 
'Accept': '*/*', 'Connection': 'keep-alive', 'origin': 'https://developer.zoom.us', 
'Authorization': 'Bearer ...',
 'Content-Type': 'application/json', 'Content-Length': '24'}

So, probably Zoom do not want to see 'Host' header, which is strange, but may be.

I cannot find any way to remove thi built-in header. I've tried:

  async with aiohttp.ClientSession() as session: 
            sessiom.headers.clear()
            async with session.patch(url, json=body, headers=post_headers ) as resp:

but no luck.

Any ideas?

question from:https://stackoverflow.com/questions/65841898/how-to-remove-built-in-headers-of-aiohttp-clientsession

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...