请求python 500内部错误

时间:2017-08-15 22:02:05

标签: python-requests

这是我的代码,大部分时间最后一个卷曲得到500错误,有人可以向我解释为什么会发生这种情况我在这里是新手!

 headers = {"Accept-Encoding": "gzip, deflate, sdch, br",
            "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Connection": "keep-alive --compressed"}
            url_ = "https://www.apct.gov.in/apportal/index.aspx"
            r = requests.get(url_,headers=headers)
            #open("/tmp/1.html","w").write(r.content)    
            c1 = r.cookies

            headers = {
        'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Referer': 'https://www.apct.gov.in/apportal/index.html',
        'Connection': 'keep-alive --compressed'}


            url = "https://www.apct.gov.in/apportal/index.aspx"
            r1 = requests.get(url,headers=headers,cookies=c1)
            c2 = r1.cookies
            # f = open("/tmp/1.html","w+")
            # f.write(r.content)
            url = "https://www.apct.gov.in/apportal/Search/ViewAPVATdealers.aspx"
            time.sleep(2.5) 



            headers = {  'Accept-Encoding': 'gzip, deflate, sdch, br',
        'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Referer': 'https://www.apct.gov.in/apportal/index.html',
        'Connection': 'keep-alive'}



            #r = requests.get(url,headers=headers,cookies=c2,timeout=60,verify=True)
            Cert ='certifi.old_where()'
            r = requests.get('https://www.apct.gov.in/apportal/Search/ViewAPVATdealers.aspx', headers=headers, cookies=c2,verify=certifi.old_where())
            r = requests.get('https://www.apct.gov.in/apportal/Search/ViewAPVATdealers.aspx', headers=headers, cookies=c2, timeout=60,verify=True)
            soup = BeautifulSoup(r.content)
            try: 
                view_state = soup.find('input', attrs={'id': '__VIEWSTATE'}).get("value")
            except:
                time.sleep(2.5)
                r = requests.get('https://www.apct.gov.in/apportal/Search/ViewAPVATdealers.aspx', headers=headers, cookies=c2, timeout=60,verify=True)
                 #pdb.set_trace()
            # r = requests.get(url,headers=headers,cookies=c2,timeout=60, verify=False)
            c3 = r.cookies
            soup = BeautifulSoup(r.content)

这是我上面的代码,最后一次卷曲大部分时间都是500错误 - 有人可以向我解释为什么会这样吗

0 个答案:

没有答案