2016-04-26 4 views
2

ScrapyのデフォルトのRetryMiddlewareを使用して、失敗したURLを再ダウンロードしようとしています。私はそのようなページを処理したいと思います。応答に429のステータスコードがあります( "Too Many Requests")。Scaryリトライミドルウェアが標準外httpステータスコードで失敗する

しかし、私はエラー

Traceback (most recent call last): 
    File "/home/vagrant/parse/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 588, in _runCallbacks 
    current.result = callback(current.result, *args, **kw) 
    File "/home/vagrant/parse/local/lib/python2.7/site-packages/scrapy/core/downloader/middleware.py", line 46, in process_response 
    response = method(request=request, response=response, spider=spider) 
    File "/home/vagrant/parse/local/lib/python2.7/site-packages/scrapy/downloadermiddlewares/retry.py", line 58, in process_response 
    reason = response_status_message(response.status) 
    File "/home/vagrant/parse/local/lib/python2.7/site-packages/scrapy/utils/response.py", line 58, in response_status_message 
    reason = http.RESPONSES.get(int(status)).decode('utf8', errors='replace') 
AttributeError: 'NoneType' object has no attribute 'decode' 

を得た私は、デバッグの問題にしようとしたScrapy RetryMiddlewareが実際に以前の失敗の理由を定義するためのページを試してダウンロードを再試行する前にことがわかりました。 だから、response_status_message方法は、それがねじれたレスポンス方式http.RESPONSES.get(int(status))を使用して応答文字列を取得するには例えば

>>> response_status_message(404) 
    '404 Not Found' 

、ステータスコードとステータステキストを使用して文字列を作成してみてください。しかし、get()のデフォルトパラメータを使用しないカスタムHTTPステータスコードの場合は、文字列の代わりにNoneTypeを返します。

したがって、ScrapyはNoneTypeのためにdecode('utf8', errors='replace')を呼び出しようとします。

これを回避する可能性はありますか?

答えて

3

実際にはScrapyライブラリのバグです。しかし、すでにthis commitに固定されており、RC1.1に置かれています。changelogs

+1

右にあります。これは問題です:https://github.com/scrapy/scrapy/pull/1857 –

関連する問題