-
Notifications
You must be signed in to change notification settings - Fork 283
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
Add a post method that allows sending binary data #224
Conversation
There are more details on the issue provided in this SO post https://stackoverflow.com/questions/54907281/robot-framework-send-binary-data-in-post-request-body-with |
I don't know much about this part but isn't the |
@lucagiove I assume that would be a different beast. The SO post explains the issue clearly. That would be a part of relevant request's documentation https://2.python-requests.org/en/master/user/advanced/#streaming-uploads |
Sorry I missed to read the Stack Overflow I'll have a read. |
Looks like the patch is bit old now. I take a look at rebasing it... |
Before working on it let me see if it's a feature that I would merge and in case how could be properly integrated I'll let you know soon. |
Hi, I had a look at original requests library code when |
Alright. I think that makes sense. Let me rebase onto latest master and update my pull request according to your suggestions. |
Gr8 remind to add tests and documentation! |
A few tests got broken I'm working on them.. Now I remember why I added a separate method for 'binary' post. The downsides are:
I hope these limitations are OK. I let you know when the tests are fixed |
I could, of course, add another keyword for closing a file handler.. not sure if it fits the design though :) Another thought is to close a handle in post() method. But that doesn't look good too. |
552b206
to
8f1ce9b
Compare
Alright, I went the second way and close a handle right after POST request. Not sure what happens if exception is thrown on the way though. The tests run. Please take a look and let me know what you think. |
Hi! Thank you for your work! About problem of multiple check of data: in the near future I want to remove all the 'data' parsing and pass directly to requests library, so this should be covered. Instead regarding the open file you're right since the library is global I think file descriptor would not be closed automatically (except if requests does it automatically). |
I didn't check yet the code I was just answering to the previous comments. |
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.
I think the approach is valid, some minor changes and can be integrated.
Updated according to the comments |
if you give me write access to the branch I'd like to add some small changes before merging |
Never did that before. Sent you an Email. Please check if that would be enough |
@UVV-gh I was wandering how to explain the difference between using the file descriptor and |
I think multipart is related to "files" only. File descriptor is used for continuous data stream. Probably makes sense just to refer to official requests documentation, doesn't it? |
A new keyword allows to pass file descriptor to python requests, which then reads a binary file directly without loading it into memory Signed-off-by: Vyacheslav Yurkov <Vyacheslav.Yurkov@bruker.com>
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.
Before merging I want to do a test comparing file descriptor and files usage.
Not needed, trying to rename and add more doc. |
Renamed |
Looks fine for me. As for the docs, it's up to you. Looking briefly through the documentation, I didn't find much of the description of other features. On the other hand, unit tests cover most of the use cases ;) |
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.
Manage OSError exception on missing file
When the data to be sent comes from rather big file, it is more
efficient to read them from the file directly.
Providing data as a parameter to the exising post method could cause
extremely high memory usage.
Signed-off-by: Vyacheslav Yurkov Vyacheslav.Yurkov@bruker.com