首页 > 解决方案 > UnicodeEncodeError:“latin-1”编解码器无法在位置 0 编码字符“\u201d”:序数不在范围内(256)

问题描述

如果有人知道帮助我,我对 Instagram 上的请求有疑问。

这是代码:

import requests

username = input('user: ')

headers = {
    'accept':'*/*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-ZW,en-US;q=0.9,en;q=0.8',
    'content-length': '84',
    'content-type': 'application/x-www-form-urlencoded',
    'cookie': 'ig_cb=2; ig_did=9A4D7DF8-A4A7-4061-A279-9B69C4683ED2; mid=YED50AAEAAGr9ZEXMr25akKRsufT; shbid=14062; rur=ATN; shbts=1619229397.0332613; csrftoken=Pa0VXyUGq674IOlySdbKFFLSGmhHWXQu',
    'origin': 'https://www.instagram.com',
    'referer':'https://www.instagram.com/accounts/password/reset/',
    'sec-ch-ua': '”Google Chrome";v="89", "Chromium";v="89", ";Not\"A\\Brand";v="99”',
    'sec-ch-ua-mobile': '?1',
    'sec-fetch-dest':'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Mobile Safari/537.36',
    'x-csrftoken': 'Pa0VXyUGq674IOlySdbKFFLSGmhHWXQu',
    'x-ig-app-id': '1217981644879628',
    'x-ig-www-claim': 'hmac.AR1kp8P0iLWIGnK2piGMehJw2lZQaN68UqFoWWr4QtEB0gPY',
    'x-instagram-ajax': '822bad258fea',
    'x-requested-with': 'XMLHttpRequest'
}

data = {
    'email_or_username': username
}

req = requests.post('https://www.instagram.com/accounts/account_recovery_send_ajax/', headers=headers , data=data).text

print(req)

标签: pythonpython-requestsinstagram

解决方案


sec-ch-ua标题的值以一个奇怪的字符开头。将其替换为"


推荐阅读