我正在學習扭曲嘗試構建RSS聚合器。當我嘗試建立使用Web代理請求,有人告訴我,我沒有提供URL參數爲字節:扭曲的代理將不會建立字節的請求
[Failure instance: Traceback (failure with no frames): <class 'twisted.web._newclient.RequestGenerationFailed'>: [<twisted.python.failure.Failure builtins.TypeError: sequence item 0: expected a bytes-like object, str found>]
但我認爲我所做的:
from twisted.internet import reactor
from twisted.web.client import Agent
def request_sent(response):
print ('I got something!')
def request_failed(reason):
print (reason)
def feed_loader_main():
"""
Starts and manage the reactor
"""
agent = Agent(reactor)
d = agent.request(
'GET',
'http://www.example.com'.encode('utf8') ##### <- HERE
)
d.addCallback(request_sent)
d.addErrback(request_failed)
print ('Firing reactor!')
reactor.run()
if __name__ == '__main__':
feed_loader_main()
它是扭曲的黑色魔術在這裏發生還是僅僅是糟糕的編碼?
你可以編輯你的問題,包括Twisted和Python版本號嗎? 'Agent'和Python 3有一個問題,但我相信它剛剛解決了。儘管如此,嘗試用'b'加前綴字符串(如果你使用Python 3) – yorodm