New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PreparedRequest.dump() #3014
PreparedRequest.dump() #3014
Conversation
kennethreitz
commented
Feb 14, 2016
I think |
I find it entertaining how this showcases just how much we completely disregard header order. |
Thinking of removing Response's render. |
Maybe |
This reverts commit 6cd586d.
@Lukasa hmmm, that works. |
This looks exactly like what I was hoping for. A couple of comments (feel free to disregard and ship anyway, I'm already happy):
|
@EmilStenstrom |
dump() works for me! |
headers='\n'.join('{}: {}'.format(k, v) for k, v in self.headers.items()), | ||
)) | ||
if body and self.body: | ||
r += '\n\n{body}'.format(body=self.body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if body is a file-like object? This won't render the way you expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same is true for generators and other weird iterators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is to say, it doesn't make sense to handle this differently from how the toolbelt already handles this. We puzzled out how to do this properly over there months ago and the code should be liftable to avoid having to reinvent the wheel and catch the same problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, they're represented by their repr, which seems like a perfectly fine solution to me. What behavior does the toolbelt exhibit in that scenario?
I agree with @EmilStenstrom. I don't like that much either. It's confusing and may make some people think we're doing some weird protocol instead of HTTP. |
Concrete suggestion of syntax for dump(): >>> import requests
>>> r = requests.get('http://httpbin.org/ip')
>>> r.request
<PreparedRequest [GET]>
>>> r.request.dump()
<PreparedRequest [
GET http://httpbin.org/ip
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.9.1
]> |
Any rationale for removing Response.dump()? I find it really useful for debugging a remote service in the same way that Request.dump() is useful. |
@EmilStenstrom hmm, that's not a bad way to present it! I like it. For the record, I'm still not 100% on including this. I'm still tossing the idea back and forth in my mind. This syntax definitely helps, though. This syntax also helps support the inclusion of |
@EmilStenstrom updated the syntax.
|
I'm very happy with how this turned out, and by also including Response.dump() all three of my concerns have been delt with. It's ready to ship in my mind. |
@EmilStenstrom as soon as I'm done perfecting |
That's why I don't care that much either way. It's not something I'd use much. I care about the entire feature, not the colouring specifically |
It's entirely possible I'm simply just not aware of how to do this, but this appears to be an incredibly easy way of doing this when needed. |
|
||
# Prepare body for dump. | ||
if body: | ||
# Add an extra newline; gotta keep 'em seperated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: "seperated" ~> "separated"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Also worth noting that we're re-implementing part of https://github.com/jkbrzt/httpie |
Random thoughts:
No further 👍s or 👎s needed at this point, but random anecdotes are more than welcome! |
My cat loves leather chairs. Doesn't like boxes at all. |
When thinking about this, know that there are two different features included here:
|
@EmilStenstrom absolutely, that'll happen no matter what. :) (unless I change my mind, for some reason) |
I don't actually think including the pretty formatting matters in any way, shape, or form, to be completely honest. Meaning, I see absolutely no reason not to. I think it's a nice feature, and I would be very pleasantly surprised to find that level of polish in my favorite HTTP library. That being said, I'm taking extra time to be considerate of @Lukasa and @sigmavirus24's objections (regardless of final result). |
My cat also loves hiding inside my recliner. |
And I'd be very confused why an HTTP library is doing anything with colorized output.
Sounds like you're going to merge this regardless of our objections? If so, I'm not sure why you would take extra time. |
I like the idea of pretty-printing request bodies, but I’m uneasy about colorised output, at least in the core library. A few disconnected thoughts:
|
@sigmavirus24 if I was sure, I would have merged it a week ago :) |
e.g. I am currently leaning towards inclusion, while swaying back and forth. Simply using this thread to think out loud. |
My cat enjoys long naps on flannel blankets on couches. |
My 6-year-old goldfish is currently living in a small man-made pond at my ex-girlfriend's house. I regret that decision :P |
I avoid adopting pets because open source projects need just as much love and are just as alive (or so I try to convince myself). ;) |
So, while we're taking feedback, here's my 2¢: The philosophy of this project since about v1.0, at least as I understand it, has been to aggressively resist scope creep. We have rejected innumerably more feature requests than we've accepted, saying "no" to almost all feature requests that failed to meet one of three criteria:
As far as I can see this feature fits into none of those categories. To the first point, it is not difficult to implement this feature from outside Requests: it is exactly as hard there as it is here. The objects being used here are public and are regularly exposed to users: there's nothing that users would ordinarily be unable to find or struggle to reach. To the second point, this feature would not be used by a majority of our users. The colorizing feature in particular suffers here because it only works when printing directly to a terminal and having a user observe those responses. That is a vanishingly small use-case of requests compared to automated use, and while it's important that those users have a good experience, I don't see value in implementing something solely for them unless it meets criteria 1 or 3. The dumping feature, even ignoring colorizing, is also something that is unlikely to be used by a substantial majority of our users, particularly because it is thoroughly ill-suited to logfiles. This is for two reasons: first, the dump contains newlines which make parsing logfiles extremely unpleasant; and second, the dump is really quite verbose and contains a lot of extraneous information that will serve only to bloat log files. To the third point, the only subtlety in correctness here is not dealt with by this code, it is encouraged by this code, and that is the fact that the representation dumped here is not the representation as received from or sent to the network. It is related to those representations, but in no way conforms to them. Users who do not grasp this subtlety are, in my opinion, likely to be confused by the representation used here. The example used in the original post is great for this:
In this example the All of that goes to say that I don't believe we'd accept this feature if it came from outside the project. I think it represents a maintenance burden for the future, because once we implement this we'll need to support it, and I don't believe that it pays for that burden in utility. And I haven't even begun to mention that to implement this feature we are adding two implicit dependencies that will now require updates in order to fix bugs that affect this rendering and that will create substantial work downstream of us to unbundle. Generally speaking we have been fairly aggressive about getting features out of this library that are not required. I think this represents a step in the other direction, and I don't believe that we gain enough by doing it to justify it. Of course, @kennethreitz, this is still your project and so my opinion is only that. =) If you merge this, I'll help maintain it. |
@Lukasa failurel! The above post stated:
My cat won't leave me alone today. |
It seems to me that '2. It's a convenience feature that would be used by a substantial majority of our users.' is a no-brainer. Every Requests user who makes mistakes would like to see this output in a debugger. |
Thanks for playing @jwg4 but the instructions in this thread clearly state that only random anecdotes are welcome at this point. |
You have a cool avatar @jwg4. |
I'd like to see this included, right now I'm logging requests with a rather naive: # inside of session
def send(self, request, ...):
self._logger(self._level, "Sending request: {}".format(pformat(request.__dict__))
resp = super().send(request, ...)
self._logger(self._level, "Got back: {}".format(pformat(resp.__dict__))
return resp As for the cat tax, my cat enjoys chasing my dog off her bed. |
Closing, for now. I still think this is useful, and the branch still exists. But, something just doesn't feel right. |