Получил http.client.BadStatusLine: пока я пытаюсь запустить его на ubuntu - PullRequest
0 голосов
/ 03 августа 2020

У кого-нибудь когда-нибудь возникала такая ошибка: http.client.BadStatusLine: GET / json / version HTTP / 1.1? Я пробовал много решений в Интернете, но не нашел решения. Это происходит, когда я пытаюсь запустить его на Ubuntu, но когда я запускаю его на vscode, он работает нормально. Как придешь? Кто-нибудь знает, как это решить?

    def getRating(self,url):
        urlToScrape = url
        headers = {
        'authority': urlToScrape,
        'pragma': 'no-cache',
        'cache-control': 'no-cache',
        'dnt': '1',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'sec-fetch-site': 'none',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-dest': 'document',
        'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
        }

        session = HTMLSession()
        resp = session.get(urlToScrape)
        resp.html.render()

        productDealsReadyToScrape = soup(resp.html.html,features="lxml")


        try:
            rating = productDealsReadyToScrape.find('i', class_='a-icon a-icon-star a-star-4')  #first we check if it is a full 4 star rating
            return rating.span.text
        except:
            try:
                rating = productDealsReadyToScrape.find('i', class_='a-icon a-icon-star a-star-4-5') #first we check if it is between 4 to 5 star rating
                return rating.span.text
            except:
                try:
                    rating = productDealsReadyToScrape.find('i', class_='a-icon a-icon-star a-star-5') #first we check if it is a full 5 star rating
                    return rating.span.text
                except:
                    rating = productDealsReadyToScrape.find('span', class_='a-icon-alt') #final choice
                    return rating.text ```

...