Skip to content
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

Fixes minor issue where attachment Content-Type is being overwritten in wrapper (and dirty fix for binary attachments on python2) #321

Merged
merged 3 commits into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/xero/basemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def wrapper(*args, **kwargs):
if headers is None:
headers = {}

headers["Content-Type"] = "application/xml"
# Send xml by default, but remember we might upload a binary attachment with a custom mime-type
if "Content-Type" not in headers:
headers["Content-Type"] = "application/xml"

if isinstance(self.credentials, OAuth2Credentials):
if self.credentials.tenant_id:
Expand Down Expand Up @@ -362,7 +364,7 @@ def _put_attachment_data(
uri = "/".join([self.base_url, self.name, id, "Attachments", filename])
params = {"IncludeOnline": "true"} if include_online else {}
headers = {"Content-Type": content_type, "Content-Length": str(len(data))}
return uri, params, "put", data, headers, False
return uri, params, "put", six.BytesIO(data), headers, False

def put_attachment(self, id, filename, file, content_type, include_online=False):
"""Upload an attachment to the Xero object (from file object)."""
Expand Down