internetarchive
internetarchive copied to clipboard
Inconsistent request preparation
While working on my recent PR, I noticed that the request for uploading is prepared differently when debug mode is enabled. With debugging, it uses the session's prepare_request
method:
https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L1052-L1055
Without debugging, it uses the request's prepare
method:
https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L1070-L1071
I observed header differences between the two, but I can't immediately tell which is more correct, hence why I'm filing an issue rather than a PR. Note that the session.headers
do get copied into the request directly inside _build_request
. Changing the non-debug code to use self.session.prepare_request
breaks several tests, too.
There's another case in Item.modify_metadata
where the code directly contradicts the preceding comment:
https://github.com/jjjake/internetarchive/blob/6e2321652ab2bd13c517dabf5a6e01f420bca380/internetarchive/item.py#L840-L842