Open prat0318 opened 10 years ago
Code showcasing the difference:
import httpretty
from twisted.internet import reactor
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
import requests
@httpretty.activate
def main():
httpretty.register_uri(
httpretty.GET, "http://exampleqwert.com")
agent = Agent(reactor)
d = agent.request(
'GET',
'http://exampleqwert.com/',
Headers({}),
None)
def cbResponse(ignored):
print 'Response received from Async: %s' % ignored.code
d.addCallback(cbResponse)
def cbShutdown(ignored): reactor.stop()
d.addBoth(cbShutdown)
reactor.run()
print 'Response received from Sync: %s' % \
requests.get('http://exampleqwert.com').status_code
main()
gives output as:
Response received from Async: 403
Response received from Sync: 200
For Async, it tries to read from the localhost, with my apache localhost server giving 403. But why is it reading localhost?
I am trying to mock my HTTP requests using httpretty for Twisted web client agent but every time i am getting a
Connection refused error
. Is Twisted Agent not supported or am i missing something? Has it worked for anyone else?