Python AttributeError:“请求”对象没有属性“方法”
我得到一个奇怪的AttributeError:“请求”对象没有属性“方法” 以下是原始代码:Python AttributeError:“请求”对象没有属性“方法”,python,web-crawler,scrapy,Python,Web Crawler,Scrapy,我得到一个奇怪的AttributeError:“请求”对象没有属性“方法” 以下是原始代码: class ModularSpider(CrawlSpider): name = 'modular_spider' allowed_domains = ['fatsecret.com'] login_url = 'https://www.fatsecret.com/Auth.aspx?pa=s' start_urls = ['http://www.fatsecret.co
class ModularSpider(CrawlSpider):
name = 'modular_spider'
allowed_domains = ['fatsecret.com']
login_url = 'https://www.fatsecret.com/Auth.aspx?pa=s'
start_urls = ['http://www.fatsecret.com/member/dorindam59']
rules = [
# main rule - process members page
Rule(
LinkExtractor(
allow='member\/[^\/\?]+$',
deny='inweb' # deny my own user
),
follow=True,
callback='schedule'
),
]
def schedule(self, response):
print 10 * "$", response.url
import pdb
pdb.set_trace()
r = Request(url=response.url
# callback=users.parse_user,
# dont_filter=True,
# priority=1
)
print 10 * "END"
print r
return
... (code continues)
这是我做的一些调查
> /Users/thalesfc/Envs/inweb/lib/python2.7/site-packages/scrapy/http/response/__init__.py(34)_get_url()
-> def _get_url(self):
(Pdb) s
> /Users/thalesfc/Envs/inweb/lib/python2.7/site- packages/scrapy/http/response/__init__.py(35)_get_url()
-> return self._url
(Pdb) s
--Return--
> /Users/thalesfc/Envs/inweb/lib/python2.7/site-packages/scrapy/http/response/__init__.py(35)_get_url()- >'http://www.f...onna+Mashburn'
-> return self._url
(Pdb) s
--Call--
> /Users/thalesfc/Envs/inweb/lib/python2.7/site- packages/scrapy/utils/trackref.py(28)__new__()
-> def __new__(cls, *args, **kwargs):
(Pdb) args
cls = <class 'scrapy.http.request.Request'>
args = ()
kwargs = {'url': 'http://www.fatsecret.com/member/Donna+Mashburn'}
(Pdb) object.__new__(cls)
*** AttributeError: 'Request' object has no attribute 'method'
(Pdb) cls
<class 'scrapy.http.request.Request'>
我知道也许我犯了一些基本的错误,但在这里或StackOverflow上找不到相关的东西
PS:我正在运行scrapy版本1.0.3
PS2:我已经试过重新安装scrapy了
PS3:当我打开一个普通的ipython时,我可以毫无问题地创建一个请求:p
对我来说,它在1.0.3剪贴版中运行良好,也许删除你的.pyc文件是值得的。在这种情况下,这可能是一个问题
包含编译代码的.pyc文件通常会在与.py文件相同的目录中创建。问题似乎出在导入中。您可以发布您导入的库吗?从scrapy import FormRequest,Spider,从scrapy.linkextractor导入LinkExtractorI的请求导入配置导入日志也尝试导入请求,如:从scrapy.http导入请求导入a,从scrapy.http.Request导入请求导入b。没有一个有效。我会测试它并让你知道。