首页 > 解决方案 > POST 请求运行没有错误,但没有做它应该做的事

问题描述

所以我在请求方面遇到了一些麻烦,我不知道为什么会这样。我之前就意识到了这一点,但我认为这是我自己的事情(可能仍然是,但我不知道它是什么,因此提出了问题)我正在为 Instagram 编写脚本。我得到它来创建 Instagram 帐户就好了。但是我希望它跟随我想要的人。这是我使用的代码:

    pat = '/web/friendships/' + e + '/follow/'
headers = {
    'authority': 'www.instagram.com',
    'method': 'POST',
    'path': pat,
    'scheme': 'https',
    'accept': '*/*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9,es;q=0.8,zh-CN;q=0.7,zh;q=0.6',
    'content-length': '0',
    'origin': 'https://www.instagram.com',
    'referer': link,
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36',
    'x-csrftoken': 'eARRsWAqOvY73Xi9Fe3WLrWK9Rdxjy6o',
    'x-instagram-ajax': 'a6abd1200036',
    'x-requested-with': 'XMLHttpRequest'
}


link = 'https://www.instagram.com/web/friendships/' + e + '/follow/'
w = s.post(link, headers = headers,proxies = proxies)

print(Fore.YELLOW + time.strftime("[%Y-%m-%d %H:%M:%S]") + Fore.GREEN + 'Followed ' + e)

所以这个请求运行没有任何错误。我已经s = requests.Session()在脚本的开头设置了。AFAIK 这复制了 POST 请求,就像您在 Instagram 上关注时一样。那为什么这不起作用???脚本运行时我没有收到任何错误。

这个问题的另一个例子是我正在处理的一个 Slickdeals 脚本。我让帐户登录工作,但是当我进入列表并尝试使用请求投票时,同样的事情发生了(脚本中没有错误,但它没有投票)。我使用的代码是这样的:

cool = {
'authority': 'slickdeals.net',
'method': 'POST',
'path': '/forums/sdthreadrate_ajax.php',
'scheme': 'https',
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en,en-US;q=0.9',
'origin': 'https://slickdeals.net',
'referer': link,
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
 }
vote_up_payload = {
   'ajax': '1',
   'do': 'sdthreadratevote',
   'postid': postid,
   'vote': '1',
   'votetypeid': '1',
   'controltype': 'modern',
   'securitytoken': sec_token,
   'where_from': '/forums/sdthreadrate_ajax.php',
}
voteu = s.post('https://slickdeals.net/forums/sdthreadrate_ajax.php', 
headers = cool, data = vote_up_payload)
print('done')

那么问题是什么?为什么脚本工作但没有做它应该做的?

[编辑]:好的,Instagram 问题是有道理的。有什么理由说明为什么 slickdeals 不起作用?

标签: pythonbeautifulsouppython-requests

解决方案


推荐阅读