Updating Excel Attachment on Confluence won't save

Marisa Voss May 4, 2018

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']}")
print('')

#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
print(df.loc[item_list[int(choose)]])

#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']
       break

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

----------------------------

Below is the error: 

Traceback (most recent call last):
File "./attach.py", line 55, in <module>
print(type(wr.save()))
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
as_template=as_template))
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
self.fp.write(zinfo.FileHeader(zip64))
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__
self.close()
File "/usr/lib64/python3.6/zipfile.py", line 1681, in close
self._write_end_record()
File "/usr/lib64/python3.6/zipfile.py", line 1784, in _write_end_record
self.fp.write(endrec)
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
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
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.

Thanks,
Ann

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events