Why Unsupported Media Type Error when attaching xlsx file to Confluence?

Marisa Voss April 10, 2018

Disclaimer: I've left certain information out of the code to be kept anonymous. Also using python3 with a combination of modules like pandas, openpyxl, StyleFrame, xlrd and xlwt for formatting the Excel sheet. 

Every time I try to change the headers or media-type Confluence does not accept it. I know that I'm in the right space as far as Confluence is concerned. The file is not corrupted since I can open it in Excel. If anyone can help me on this I would greatly appreciate it. 

My code is below: 

req = requests.Session()
print("Hello")
url='https://confluence.<mycompany>.com/rest/api'
base_url = url
att = {'file': open("items-list2.xlsx", 'rb')}
headers = {"X-Atlassian-Token": "nocheck", "Content_Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "X-Content-Type-Options": "nosniff", "Accept" : "application/json"}
print("base: {} with spreadsheetml.sheet".format(base_url))
attID = 'myAttID'
r = req.get('{}/content/{}'.format(base_url, attID), headers=headers, auth = (username, password), files = att)

if (r.status_code < 300):
print(r.headers)

print(r)
print(r.text)
print(" ")
print('~~~~ failed to upload file ~~~~')

 

The Error I receive: 

~~~~~~~~~~~~
<Response [415]>
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.48 - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 415 - Unsupported Media Type</h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u>Unsupported Media Type</u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u></p><hr class="line"><h3>Apache Tomcat/8.0.48</h3></body></html>

~~~~ failed to upload file ~~~~

2 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2018

It looks like Kenny may have found an answer for a different application, and probably posted a link that would not really have helped you.

I'm afraid I don't know the right answer either, but I do know that there is nothing wrong with your file or process, as I've run into the same thing.  It is definitely something in your headers, and of them it is either the Content_Type and/or X-Content-Type-Options.

But as I typed that, I realised the most likely culprit!  Try Content-Type, not Content_Type  (if it's not that, then have another look at the values in those two)

Marisa Voss April 26, 2018

You right! Content-Type was definitely the problem. When a typo is the hardest bug to find smh.

Thank you. 

0 votes
kennyngkk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 17, 2018
  • removed as is incorrect
Marisa Voss April 18, 2018

What is correct?

Marisa Voss April 25, 2018

@kennyngkk Can you be more specific as to what is wrong and what you removed please? 

kennyngkk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 1, 2018

@Marisa Voss sorry that it took me too long to get back to you as it my fault that my . activity feed got flooded and its my fault. Yes, @Nic Brough -Adaptavist- was right. I got the wrong document for a different product and we are glad that you were able to resolve the issue on your end. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events