HTTP Status Code

codestatusdescription
100Continue继续。客户端应该继续发送请求
101Switching Protocols协议转换。在Upgrade消息头通知客户端用不同协议完成请求。在响应后,服务器将切换到该协议。通常在切换到新协议有好处时才采取该措施,比如,HTTP新版本比旧版本有优势,或者切换为实时且同步的协议以传送利用该特性的资源
200OKOK。请求的响应头或数据体将随本次响应返回
201Created新的资源已经依据请求的需要而建立,且其URI已经随Location头信息返回
202Accept服务器已接受请求,但尚未处理。最终该请求可能会也可能不会被执行。在异步操作的场合下,发送该状态码最方便。
400Bad Request坏请求。1.当前请求无法被服务器理解,不应重复提交未修改的该请求。2.请求参数有误
401Unauthorized非法的。当前请求需要用户验证。客户端可以重复提交一个包含恰当的 Authorization 头信息的请求。如果当前请求已经包含了 Authorization 证书,那么401响应代表着服务器验证已经拒绝了那些证书。
402Payment Required需要付款。该功能待实现(保留值)。
403Forbidden禁用访问。服务器已经理解请求,但是拒绝执行它。
404Not Found无法找到。请求希望得到的资源在服务器未找到。
405Method Not Allowed方法不被允许。请求所指定的方法不能请求对应的资源。
408Request Timeout请求超时。客户端在服务器预备等待时间内没有完成一个请求的发送。
409Conflict请求冲突。例如,在采用版本检查的环境下,PUT请求附带的版本信息与之前的某个(第三方)请求冲突,此时服务器应该返回409错误。此时,响应实体中包含两个冲突版本之间的差异比较,以便用户重新提交归并以后的新版本。
413Request Entity Too Large请求实体过大。请求提交的实体数据大小超过了服务器愿意或能够处理的范围。
414Request-URI Too Long请求URI过长。请求的URI长度超过了服务器能够解释的长度。
500Internal Server Error服务器内部错误。服务器遇到未知错误,导致无法完成请求。
501Not Implement未实现。服务器不支持当前请求所需要的某个功能。
502Bad Gateway无效网关。作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应。
503Service Unavailable服务不可用。由于临时的服务器维护或者过载,服务器无法处理请求。
504Gateway Timeout网关超时。作为网关或者代理工作的服务器尝试请求时,未能及时从上游服务器收到响应。
505HTTP Version Not SupportedHTTP版本不支持。服务器不支持,或者拒绝支持在请求中使用的 HTTP 版本。

URI 和 URL:
URI 统一资源标志符:在某一规则下能把一个资源独一无二地标识出来。
URL统一资源定位符:URL是以描述资源的位置来唯一确定一个资源。
所以,URL用定位的方式实现URI,起到URI的作用,是URI的子集。

raise KeyError(f"{self.__class__.__name__} does not support field: {key}") KeyError: 'NepuContentItem does not support field: publish_date' 2025-07-07 20:46:23 [nepudata] INFO: 开始解析页面: https://www.nepu.edu.cn/gjjl/xjjl.htm 2025-07-07 20:46:23 [scrapy.core.scraper] ERROR: Spider error processing <GET https://www.nepu.edu.cn/gjjl/xjjl.htm> (referer: None) Traceback (most recent call last): File "D:\annaCONDA\Lib\site-packages\scrapy\utils\defer.py", line 257, in iter_errback yield next(it) ^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\utils\python.py", line 312, in __next__ return next(self.data) ^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\utils\python.py", line 312, in __next__ return next(self.data) ^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\core\spidermw.py", line 104, in process_sync for r in iterable: File "D:\annaCONDA\Lib\site-packages\scrapy\spidermiddlewares\offsite.py", line 28, in <genexpr> return (r for r in result or () if self._filter(r, spider)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\core\spidermw.py", line 104, in process_sync for r in iterable: File "D:\annaCONDA\Lib\site-packages\scrapy\spidermiddlewares\referer.py", line 353, in <genexpr> return (self._set_referer(r, response) for r in result or ()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\core\spidermw.py", line 104, in process_sync for r in iterable: File "D:\annaCONDA\Lib\site-packages\scrapy\spidermiddlewares\urllength.py", line 27, in <genexpr> return (r for r in result or () if self._filter(r, spider)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\core\spidermw.py", line 104, in process_sync for r in iterable: File "D:\annaCONDA\Lib\site-packages\scrapy\spidermiddlewares\depth.py", line 31, in <genexpr> return (r for r in result or () if self._filter(r, response, spider)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\core\spidermw.py", line 104, in process_sync for r in iterable: File "C:\Users\Lenovo\nepu_spider\nepu_spider\spiders\nepudata_spider.py", line 93, in parse item = self.extract_content(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\nepu_spider\nepu_spider\spiders\nepudata_spider.py", line 175, in extract_content item['publish_date'] = publish_date ~~~~^^^^^^^^^^^^^^^^ File "D:\annaCONDA\Lib\site-packages\scrapy\item.py", line 85, in __setitem__ raise KeyError(f"{self.__class__.__name__} does not support field: {key}") KeyError: 'NepuContentItem does not support field: publish_date' 2025-07-07 20:46:23 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/yjsy/>: HTTP status code is not handled or not allowed 2025-07-07 20:46:24 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/jwc/>: HTTP status code is not handled or not allowed 2025-07-07 20:46:24 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsc/>: HTTP status code is not handled or not allowed 2025-07-07 20:46:25 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/rsc/>: HTTP status code is not handled or not allowed 2025-07-07 20:46:26 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/kyc/>: HTTP status code is not handled or not allowed 2025-07-07 20:46:26 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2020>: HTTP status code is not handled or not allowed 2025-07-07 20:46:27 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2021>: HTTP status code is not handled or not allowed 2025-07-07 20:46:28 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2022>: HTTP status code is not handled or not allowed 2025-07-07 20:46:28 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2023>: HTTP status code is not handled or not allowed 2025-07-07 20:46:29 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2024>: HTTP status code is not handled or not allowed 2025-07-07 20:46:29 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xxyw/?year=2025>: HTTP status code is not handled or not allowed 2025-07-07 20:46:30 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2020>: HTTP status code is not handled or not allowed 2025-07-07 20:46:30 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2021>: HTTP status code is not handled or not allowed 2025-07-07 20:46:31 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2022>: HTTP status code is not handled or not allowed 2025-07-07 20:46:31 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2023>: HTTP status code is not handled or not allowed 2025-07-07 20:46:32 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2024>: HTTP status code is not handled or not allowed 2025-07-07 20:46:32 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/tzgg/?year=2025>: HTTP status code is not handled or not allowed 2025-07-07 20:46:33 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2020>: HTTP status code is not handled or not allowed 2025-07-07 20:46:34 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2021>: HTTP status code is not handled or not allowed 2025-07-07 20:46:34 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2022>: HTTP status code is not handled or not allowed 2025-07-07 20:46:35 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2023>: HTTP status code is not handled or not allowed 2025-07-07 20:46:36 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2024>: HTTP status code is not handled or not allowed 2025-07-07 20:46:37 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.nepu.edu.cn/xsdt/?year=2025>: HTTP status code is not handled or not allowed 2025-07-07 20:46:37 [scrapy.core.engine] INFO: Closing spider (finished) 2025-07-07 20:46:37 [nepudata] INFO: 数据库连接已关闭 2025-07-07 20:46:37 [scrapy.statscollectors] INFO: Dumping Scrapy stats: {'downloader/request_bytes': 10178, 'downloader/request_count': 32, 'downloader/request_method_count/GET': 32, 'downloader/response_bytes': 117980, 'downloader/response_count': 32, 'downloader/response_status_count/200': 9, 'downloader/response_status_count/404': 23, 'elapsed_time_seconds': 23.999904, 'finish_reason': 'finished', 'finish_time': datetime.datetime(2025, 7, 7, 12, 46, 37, 62452), 'httpcompression/response_bytes': 187569, 'httpcompression/response_count': 9, 'httperror/response_ignored_count': 23, 'httperror/response_ignored_status_count/404': 23, 'log_count/ERROR': 9, 'log_count/INFO': 45, 'log_count/WARNING': 1, 'response_received_count': 32, 'scheduler/dequeued': 32, 'scheduler/dequeued/memory': 32, 'scheduler/enqueued': 32, 'scheduler/enqueued/memory': 32, 'spider_exceptions/KeyError': 9, 'start_time': datetime.datetime(2025, 7, 7, 12, 46, 13, 62548)} 2025-07-07 20:46:37 [scrapy.core.engine] INFO: Spider closed (finished)
最新发布
07-08
在 Scrapy 中出现 `KeyError: 'NepuContentItem does not support field: publish_date'` 错误的原因是尝试为一个未在 `Item` 类中定义的字段赋值。Scrapy 的 `Item` 类用于定义爬取数据的结构,所有需要存储的字段都必须在 `Item` 类中显式声明[^1]。 ### 解决方法 #### 1. 确保字段已在 `Item` 类中定义 首先检查你的 `Item` 类(例如 `NepuContentItem`)是否已经定义了 `publish_date` 字段: ```python import scrapy class NepuContentItem(scrapy.Item): title = scrapy.Field() content = scrapy.Field() publish_date = scrapy.Field() # 确保该字段已定义 ``` 如果尚未定义,请添加该字段并重新运行爬虫。 #### 2. 使用 `ItemLoader` 添加字段 如果你希望动态添加字段而不在 `Item` 类中显式声明,可以使用 `ItemLoader` 并设置 `loader.default_item_class` 或者使用 `dict` 来临时存储数据: ```python from scrapy.loader import ItemLoader def parse(self, response): item = ItemLoader(item=NepuContentItem()) item.add_value('title', '示例标题') item.add_value('publish_date', '2025-04-05') # 动态添加字段 yield item.load_item() ``` 或者直接使用字典来绕过 `Item` 的字段限制: ```python yield { 'title': '示例标题', 'publish_date': '2025-04-05' } ``` 注意:使用字典方式时,后续的 `Item Pipeline` 将无法自动处理这些数据,需手动处理。 #### 3. 检查字段名称拼写 确保你在爬虫中使用的字段名与 `Item` 类中定义的字段名完全一致,包括大小写和下划线使用: ```python # 正确 item['publish_date'] = '2025-04-05' # 错误(拼写错误) item['publishDate'] = '2025-04-05' ``` #### 4. 使用 `try-except` 处理异常字段 如果你不确定某些字段是否存在于 `Item` 中,可以使用 `try-except` 块进行容错处理: ```python try: item['publish_date'] = response.meta.get('date') except KeyError: self.logger.warning("字段 publish_date 未在 NepuContentItem 中定义") ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值