2015-09-01 82 views
0

我得到一個奇怪的AttributeError的:「請」對象有沒有屬性「方法」 這裏是原代碼: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.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'> 

我知道也許我只是做了一些基本的錯誤,但無法找到這裏或在計算器上相關的東西。

  • PS:我正在運行scrapy版本1.0.3
  • PS2:我已經嘗試過重新安裝scrapy
  • PS3:當我打開一個正常的IPython,我可以創建一個沒有問題的一個請求:對
+0

似乎問題出在導入。你可以發佈你導入的庫嗎? –

+0

從scrapy進口FormRequest,蜘蛛,請求 進口配置 進口記錄 從scrapy.linkextractors導入LinkExtractor – thalesfc

+0

我也tryed導入像請求:(1)從scrapy.http導入請求和(b)從scrapy.http。請求導入請求。他們都沒有工作過。 – thalesfc

回答

0

對我來說,它在1.0.3 scrapy版本中工作得很好,也許它值得刪除你的.pyc文件。在這種情況下可能會出現問題

包含編譯代碼的.pyc文件通常會在.py文件所在的目錄中創建。

+0

我會測試它,讓你知道。 – thalesfc

相關問題