Updating Excel Attachment on Confluence won't save Edited

For some reason my excel sheet will update, but by the time I attach it to Confluence the file reverts back to the original. What am I doing wrong here? Maybe because of my GET confuses it? So the POST reverts back somehow.. not sure. (EDIT added the requests in code)

Code: -------------------------

import json

import pandas as pd

import xlrd

import xlwt

import yaml

import requests

import logging

from openpyxl import Workbook

from openpyxl import load_workbook

from collections import defaultdict


config = yaml.load(open('config.yaml'))

username = config['confluence username']
password = config['confluence password']

x = pd.ExcelFile('items-list4.xlsx')
df = pd.read_excel(x, index_col=0)
target = load_workbook('items-list4.xlsx')
item_list = {}
count = 0
for i in df.index:
count = count + 1
item_list[count] = i

for x,y in item_list.items():
print(f"{x} - {y}")
choose = input("Choose item number you want to update: ")
curitm = item_list[int(choose)]
curqty = df.loc[item_list[int(choose)], 'Qty']
print(f"chosen value: {item_list[int(choose)]}")
print(f"value's quantity: {df.loc[item_list[int(choose)], 'Qty']}")

#updating the quantity
qtyin = input(f"Enter the new quantity number for {item_list[int(choose)]}: ")
df.loc[item_list[int(choose)], 'Qty'] = qtyin
curqty = qtyin

#creating the excel writer
wr= pd.ExcelWriter(x, engine='openpyxl')
wr.book = target
df.to_excel(wr, "Sheet1", startcol=0, startrow=0, header=True, index=False)
wr.save() # THIS LINE FOR SOME REASON DOESN'T save, openpyxl is looking for an int?? 

req = requests.Session()

opener = open('items-list4.xlsx', 'rb')
att = {'file': opener}
headers = {'X-Atlassian-Token': 'nocheck'}

r1 = req.get("{}/content/{}/child/attachment".format(base_url, page_id), auth = (username, password)).json()

for r,y in r1.items():
       attachment_id = y[0]['id']

r2 = req.post("{}/content/{}/child/attachment".format(base_url, page_id), headers=headers, auth = (username, password), files = att)
if (r2.status_code < 300):


Below is the error: 

Traceback (most recent call last):
File "./attach.py", line 55, in <module>
File "/usr/lib64/python3.6/site-packages/pandas/io/excel.py", line 824, in save
return self.book.save(self.path)
File "/usr/lib/python3.6/site-packages/openpyxl/workbook/workbook.py", line 298, in save
save_workbook(self, filename)
File "/usr/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 198, in save_workbook
writer.save(filename, as_template=as_template)
File "/usr/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 181, in save
self.write_data(archive, as_template=as_template)
File "/usr/lib/python3.6/site-packages/openpyxl/writer/excel.py", line 65, in write_data
File "/usr/lib64/python3.6/zipfile.py", line 1658, in writestr
with self.open(zinfo, mode='w') as dest:
File "/usr/lib64/python3.6/zipfile.py", line 1355, in open
return self._open_to_write(zinfo, force_zip64=force_zip64)
File "/usr/lib64/python3.6/zipfile.py", line 1468, in _open_to_write
File "/usr/lib64/python3.6/zipfile.py", line 723, in write
n = self.fp.write(data)
AttributeError: 'int' object has no attribute 'write'
Exception ignored in: <bound method ZipFile.__del__ of <zipfile.ZipFile [closed]>>
Traceback (most recent call last):
File "/usr/lib64/python3.6/zipfile.py", line 1663, in __del__
File "/usr/lib64/python3.6/zipfile.py", line 1681, in close
File "/usr/lib64/python3.6/zipfile.py", line 1784, in _write_end_record
File "/usr/lib64/python3.6/zipfile.py", line 723, in write
n = self.fp.write(data)
AttributeError: 'int' object has no attribute 'write'

1 answer

0 votes
Ann Worley Atlassian Team May 22, 2018

Hi Marisa,

Is it possible there is an integer where there should be a different data type? The error I am focussed on is:

AttributeError: 'int' object has no attribute 'write'

I found a Stack Overflow post about that error that may help: AttributeError: 'int' object has no attribute 'write'

Looking forward to hearing whether it helps.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

456 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you