简体   繁体   English

邮差得到状态代码200没有标题GET METHOD但python请求得到500错误

[英]Postman get status code 200 with no headers GET METHOD but python requests gets 500 error

[enter image description here][1]As a title, I can't get the content of website with python requests , but works with postman [在此处输入图片说明] [1]作为标题,我无法通过python requests获取网站内容,但与postman

I had tried to connect website with postman and get content of the web page, but I couldn't achieve it when I executed the code that was produced by postman like below, Instead, I got error 500 status code with python 2 and 3. 我曾尝试将网站与邮递员联系起来并获取网页的内容,但是当我执行邮差如下所示的代码时,我无法实现它,相反,我得到了错误500状态代码与python 2和3。

import requests 导入请求

url = "https://www.screener.reuters.wallst.com/Stock/US/ResultsTable"

querystring = {"returnChoice":"","page":"2","sortBy":"RCCMultexCompanyName","sortDir":"A","quickscreen":"gaarp","criteria":"%5B%22StockUniverse%22%2C%22PriceEarnings%22%2C%22EPSGrowthRate%22%2C%22Region%22%2C%22SectorAndIndustry%22%2C%22PEGRatio%22%5D","Currency":"USD","PEGRatio":"%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22LSS%7C1%22%7D","SectorAndIndustry":"%7B%22industries%22%3A%5B%2257111%22%2C%2257112%22%2C%2257121%22%2C%2257131%22%2C%2257132%22%2C%2257211%22%2C%2257212%22%5D%7D","Region":"%7B%22countries%22%3A%5B%22TW%22%5D%7D","EPSGrowthRate":"%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22GTR%7C15%22%7D","PriceEarnings":"%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22GEQ%7C0%7CLEQ%7C15%22%7D","StockUniverse":"%7B%22button_inputs%22%3A%5B%22LIKE%7CUnited%2BStates%22%2C%22NOTLIKE%7CUnited%2BStates%22%5D%7D","OriginalCurrency":"USD%0A"}

headers = {
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

I excepted get 200 status code,but got 500 actually. 我除了获得200状态代码,但实际上得到500。 It is strange because postman can get right result and python cannot,even I had filled in the headers. 这很奇怪,因为邮差可以得到正确的结果而python不能,即使我填写了标题。

headers = {
    'Accept-Encoding': "gzip, deflate, br",
    'Accept-Language': "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7",
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.90 Safari/537.36',
    'Content-Type': "application/x-www-form-urlencoded",
    'Accept': "application/json",
    'X-Requested-With': "XMLHttpRequest",
    'Connection': "keep-alive",
    'cache-control': "no-cache",
    }



The below url can get content if you connect it with browser or postman but  can't  get if you connect it with python reqeusts or urllib. 

https://www.screener.reuters.wallst.com/Stock/US/ResultsTable?returnChoice=&page=2&sortBy=RCCMultexCompanyName&sortDir=A&quickscreen=gaarp&criteria=%5B%22StockUniverse%22%2C%22PriceEarnings%22%2C%22EPSGrowthRate%22%2C%22Region%22%2C%22SectorAndIndustry%22%2C%22PEGRatio%22%5D&Currency=USD&PEGRatio=%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22LSS%7C1%22%7D&SectorAndIndustry=%7B%22industries%22%3A%5B%2257111%22%2C%2257112%22%2C%2257121%22%2C%2257131%22%2C%2257132%22%2C%2257211%22%2C%2257212%22%5D%7D&Region=%7B%22countries%22%3A%5B%22TW%22%5D%7D&EPSGrowthRate=%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22GTR%7C15%22%7D&PriceEarnings=%7B%22view%22%3A%22button%22%2C%22button_inputs%22%3A%5B%5D%2C%22range_inputs%22%3A%22GEQ%7C0%7CLEQ%7C15%22%7D&StockUniverse=%7B%22button_inputs%22%3A%5B%22LIKE%7CUnited%2BStates%22%2C%22NOTLIKE%7CUnited%2BStates%22%5D%7D&OriginalCurrency=USD

And below is postman screenshot
  [1]: https://i.stack.imgur.com/DO8ev.png

I found postman will store cookie secretly even if cookies doesn't present in the python code which is postman generated with new desktop postman version. 我发现postman会秘密存储cookie,即使python代码中没有cookie,这是使用新的桌面邮递员版本生成的邮递员。

The way to get right content is to requests post below url with corrent params https://www.screener.reuters.wallst.com/Stock/US/Results It will get 500 error,but with this session I can get the content of my question. 获得正确内容的方法是使用相关的参数在url下面发帖请求https://www.screener.reuters.wallst.com/Stock/US/Results这将得到500错误,但是通过这个会话我可以得到的内容我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM