Replies: 4 comments 3 replies
-
|
I just started to use |
Beta Was this translation helpful? Give feedback.
-
|
We do something like this: Then for the consumer class we use the above as a decorator: |
Beta Was this translation helpful? Give feedback.
-
|
Interesting. I never used it that way. One thing the example has that yours doesn't is the @uplink.json decorator. Apart from that I am not sure why you are getting that error. |
Beta Was this translation helpful? Give feedback.
-
|
So as I've been working with Uplink more, this is the code I ultimately found to be the simplest way to log requests and responses going through Uplink. This could obviously be extended to give more info about the request, but for now, the URL is sufficient. from pprint import pprint
import uplink
from requests import Response
@uplink.response_handler
def response_logger(response: Response) -> Response:
"""Inspect the raw request and response objets for a transaction
To use this, add @response_logger as a decorator to an Uplink
interface method.
"""
print('Raw Request URL:', response.request.url)
print('Raw Response Status Code:', response.status_code)
print('Raw Response Headers:')
pprint(dict(response.headers))
print('Raw Response Text (decoded):')
pprint(response.json())
return response |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently using code like this:
Unfortunately, I don't actually want to use
requestsfor this, I want to usehttpxvia theuplink-httpxlibrary. So I started by trying to get it working the way I wanted it, and then I started having to comment out theHttpxClient()in the the uplink client instantiation, and delete all theasyncandawaitkeywords everywhere, and scaffold the client use with a synchronous main method, etc. It's a big pain in the butt.At this point, I'm just going to use requests during development now, and then switch to
httpxwhen I'm ready to stop developing and start using.I'd just like to be able to print or otherwise see what URL is being generated for each request. Is there a better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions