简体   繁体   English

请求库有200个响应状态,但Scrapy有500个响应状态

[英]200 response status with requests library but 500 with Scrapy

When I use make the request with the requests library, it works: 当我使用请求库发出请求时,它可以工作:

import requests


r = requests.get("https://www.opentable.de/c/raum-stuttgart-restaurants")
print r

The response is 200: 回复是200:

Response [200] 回应[200]

But when I try to do the same thing with Scrapy I get 500 response status: 但是当我尝试用Scrapy做同样的事情时,我得到500响应状态:

# -*- coding: utf-8 -*-

from scrapy.spiders import Spider
from scrapy.http import Request

from opentable.items import OpentableItem


class GermanySpider(Spider):
    name = "germany_spider"

    start_urls = [
                "https://www.opentable.de/c/raum-stuttgart-restaurants"
                ]

    def parse(self, response):
        pass

Log: 日志:

2017-05-30 23:28:33 [scrapy] INFO: Scrapy 1.0.4 started (bot: opentable)
2017-05-30 23:28:33 [scrapy] INFO: Optional features available: ssl, http11
2017-05-30 23:28:33 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'opentable.spiders', 'SPIDER_MODULES': ['op
entable.spiders'], 'BOT_NAME': 'opentable'}
2017-05-30 23:28:36 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2017-05-30 23:28:38 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAg
entMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMidd
leware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2017-05-30 23:28:39 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware
, UrlLengthMiddleware, DepthMiddleware
2017-05-30 23:28:39 [scrapy] INFO: Enabled item pipelines:
2017-05-30 23:28:39 [scrapy] INFO: Spider opened
2017-05-30 23:28:39 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2017-05-30 23:28:39 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2017-05-30 23:28:42 [scrapy] DEBUG: Retrying <GET https://www.opentable.de/rest_list.aspx?m=227> (failed 1 times): 500 I
nternal Server Error
2017-05-30 23:28:43 [scrapy] DEBUG: Retrying <GET https://www.opentable.de/rest_list.aspx?m=227> (failed 2 times): 500 I
nternal Server Error
2017-05-30 23:28:44 [scrapy] DEBUG: Gave up retrying <GET https://www.opentable.de/rest_list.aspx?m=227> (failed 3 times
): 500 Internal Server Error
2017-05-30 23:28:44 [scrapy] DEBUG: Crawled (500) <GET https://www.opentable.de/rest_list.aspx?m=227> (referer: None)
2017-05-30 23:28:44 [scrapy] DEBUG: Ignoring response <500 https://www.opentable.de/rest_list.aspx?m=227>: HTTP status c
ode is not handled or not allowed
2017-05-30 23:28:44 [scrapy] INFO: Closing spider (finished)
2017-05-30 23:28:44 [scrapy] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 1344,
 'downloader/request_count': 3,
 'downloader/request_method_count/GET': 3,
 'downloader/response_bytes': 1837,
 'downloader/response_count': 3,
 'downloader/response_status_count/500': 3,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2017, 5, 30, 18, 28, 44, 745000),
 'log_count/DEBUG': 6,
 'log_count/INFO': 7,
 'response_received_count': 1,
 'scheduler/dequeued': 3,
 'scheduler/dequeued/memory': 3,
 'scheduler/enqueued': 3,
 'scheduler/enqueued/memory': 3,
 'start_time': datetime.datetime(2017, 5, 30, 18, 28, 39, 76000)}
2017-05-30 23:28:44 [scrapy] INFO: Spider closed (finished)

At scrapinghub there is the same response. 在scrapinghub有相同的反应。 Why does it happen? 为什么会这样? What's the difference between a request with requests and a request with Scrapy? 请求请求与Scrapy请求之间有什么区别?

I've got the same problem and, after debugging Scrapy requests, I've found it send these headers by default: 我有同样的问题,在调试Scrapy请求后,我发现它默认发送这些头:

Accept : text/html,application/xhtml+xml,application/xml;q=0.9, / ;q=0.8 接受 :text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8

Accept-Encoding : gzip,deflate Accept-Encoding :gzip,deflate

For me it was the Accept header that was causing the error 500. After setting it to */* the server returned a 200 response. 对我来说,是导致错误500的Accept标头。在将其设置为* / *之后,服务器返回了200响应。

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

相关问题 Scrapy抓取了0页,响应状态为200 - Scrapy crawled 0 pages with 200 response status 防止忽略非 200 响应状态 - Scrapy - Prevent ignoring non 200 response status - Scrapy 状态 200 但我没有得到一些响应。 python 请求 - status 200 but I dont get some of the response. python requests 获得200响应但未使用python请求库登录 - Getting 200 response but not logging in using python requests library 我正在尝试为scrapy请求打印301状态。 但是,页面重定向并每次显示200 - I am trying to print the 301 status for scrapy requests. But, the page redirects and shows 200 everytime Python requests.post() 方法命令返回 200 status_code 属性而不是 500 - Python requests.post() method command returns 200 status_code attribute instead of 500 邮差得到状态代码200没有标题GET METHOD但python请求得到500错误 - Postman get status code 200 with no headers GET METHOD but python requests gets 500 error 如何在scrapy中缓存仅http状态200? - How to cache Only http status 200 in scrapy? 为什么请求响应对象 __bool__ 检查 200 &lt;= status &lt; 400? - Why does requests response object __bool__ check for 200 <= status < 400? 使用 python 请求库登录网页,状态码 200,解析失败且未经授权的页面仍然未经授权 - Login to webpage with python requests library, status code 200, failing to parse and unauthorized pages still unauthorized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM