我试图在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())
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行试图从您的作用域中读取两个名字。twisted
和 keyAndCert
. 这两个名字都不符合你在范围内输入的两个名字 (ClientContextFacotry
和 PrivateCertificate
).
幸运的是,您试图使用的是 twisted
名,显然是为了达到 PrivateCertificate
. 您可以更换 twisted.internet.ssl.PrivateCertificate
用实际在你的范围内的名称。PrivateCertificate
.
一旦你解决了这个问题,你就会得到一个关于 keyAndCert
因为在你的作用域中也没有定义(除非它真的是,但你省略了定义它的代码)。