Scrapy contextfactory.py。在iPython中出现命名错误。试图使用twisted库

问题描述 投票:1回答:1

我试图在scrapy shell中运行一个fetch命令。错误指向contextfactory.py。twisted库已经包含在我的虚拟环境中。我如何解决这个错误?

from twisted.internet.ssl import ClientContextFactory
from twisted.internet.ssl import PrivateCertificate 



myClientCert = twisted.internet.ssl.PrivateCertificate.load(keyAndCert.read())

enter image description here

enter image description here

python scrapy twisted
1个回答
1
投票
from twisted.internet.ssl import ClientContextFactory
from twisted.internet.ssl import PrivateCertificate 

myClientCert = twisted.internet.ssl.PrivateCertificate.load(keyAndCert.read())

第1行把 ClientContextFactory 的名称进入您的范围。 第2行将 PrivateCertificate 名字到你的作用域中。 第4行试图从您的作用域中读取两个名字。twistedkeyAndCert. 这两个名字都不符合你在范围内输入的两个名字 (ClientContextFacotryPrivateCertificate).

幸运的是,您试图使用的是 twisted 名,显然是为了达到 PrivateCertificate. 您可以更换 twisted.internet.ssl.PrivateCertificate 用实际在你的范围内的名称。PrivateCertificate.

一旦你解决了这个问题,你就会得到一个关于 keyAndCert 因为在你的作用域中也没有定义(除非它真的是,但你省略了定义它的代码)。

© www.soinside.com 2019 - 2024. All rights reserved.