您的位置:首页 > 财经 > 产业 > scrapy出现OSError: could not get source code错误解决

scrapy出现OSError: could not get source code错误解决

2024/11/17 18:46:00 来源:https://blog.csdn.net/weixin_51111267/article/details/140722341  浏览:    关键词:scrapy出现OSError: could not get source code错误解决

出现问题如下:

Traceback (most recent call last):File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\defer.py", line 73, in mustbe_deferredresult = f(*args, **kw)File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\core\spidermw.py", line 92, in _process_spider_inputreturn scrape_func(response, request, spider)File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\core\scraper.py", line 200, in call_spiderwarn_on_generator_with_return_value(spider, callback)File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\misc.py", line 258, in warn_on_generator_with_return_valueif is_generator_with_return_value(callable):File "C:\Users\admin\Desktop\crawler_scrapy_us\venv\lib\site-packages\scrapy\utils\misc.py", line 234, in is_generator_with_return_valuesrc = inspect.getsource(func)File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1139, in getsourcelines, lnum = getsourcelines(object)File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1121, in getsourcelineslines, lnum = findsource(object)File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 958, in findsourceraise OSError('could not get source code')
OSError: could not get source code

原因:想必是你小子手动创建了爬虫文件,这样出现了编码问题

解决办法:爬虫文件添加编码头注释 #coding=utf8

#coding=utf8
import scrapy

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com