重複を作成したくないのですが、周りを見回して(スタックオーバーフローや他のフォーラム)、同様の質問を見つけましたが、どれも私の問題を解決しませんでした。
DBにクエリを実行し、PandasでDataFrameを作成して、Excelファイルに書き込むだけのPythonコードがあります。
コードはローカルで問題なく機能しましたが、サーバーに導入すると、次のエラーが発生し始めます。
File "Test.py", line 34, in <module>
test()
File "Test.py", line 31, in test
ex.generate_file()
File "/home/carlo/Test/Utility/ExportExcell.py", line 96, in generate_file
writer.save()
File "/usr/local/lib/python2.7/dist-packages/pandas/io/excel.py", line 1952, in save
return self.book.close()
File "/usr/local/lib/python2.7/dist-packages/xlsxwriter/workbook.py", line 306, in close
self._store_workbook()
File "/usr/local/lib/python2.7/dist-packages/xlsxwriter/workbook.py", line 677, in _store_workbook
xlsx_file.write(os_filename, xml_filename)
File "/usr/lib/python2.7/zipfile.py", line 1135, in write
zinfo = ZipInfo(arcname, date_time)
File "/usr/lib/python2.7/zipfile.py", line 305, in __init__
raise ValueError('ZIP does not support timestamps before 1980')
ValueError: ZIP does not support timestamps before 1980
それがすべて問題ないことを確認するために、私はDataFrameを印刷しました。ローカルで実行すると、問題なくexcellファイルが生成されるため、見栄えがよくなります。
Computer_System_Memory_Size Count_of_HostName Disk_Total_Size Number_of_CPU OS_Family
0 5736053088256 70 6072238035456 282660 Windows
1 96159653888 607 96630589440 2451066 vCenter
2 0 9 0 36342 Virtualization
3 2469361287143424 37 2389533519619072 149406 Unix
4 3691651514368 90 5817485303808 363420 Linux
ここにタイムスタンプが表示されません。これは私のコードの一部です。
pivot = pd.DataFrame.from_dict(pivot) #pivot= information extracted from DB
pd.to_numeric(pivot['Count_of_HostName'], downcast='signed')#try to enforce to be a numeric value in case it get confused with a datetime
pd.to_numeric(pivot['Disk_Total_Size'], downcast='signed')#try to enforce to be a numeric value in case it get confused with a datetime
pd.to_numeric(pivot['Computer_System_Memory_Size'], downcast='signed')#try to enforce to be a numeric value in case it get confused with a datetime
pd.to_numeric(pivot['Number_of_CPU'], downcast='signed')#try to enforce to be a numeric value in case it get confused with a datetime
print pivot
name = 'TempReport/Report.xlsx'#set-up file name
writer = pd.ExcelWriter(name, engine='xlsxwriter')#create excel with file name
pivot.to_excel(writer, 'Pivot', index=False)#introduce my data to excel
writer.save()#write to file, it's where it fail
「ZIPは1980年以前のタイムスタンプをサポートしていません」というエラーが表示されない限り、Ubuntu 16.04サーバーで機能しない理由を誰かが知っていますか?私は多くのこと、ライブラリのバージョンをチェックし、データがないことを確認しました
XlsxWriterは、XLSXファイルを構成する個々のXMLファイルを設定します。作成日は1980年1月1日で、これは(私が思うに)ZIPエポックでExcelで使用される日付です。これにより、同じ入力データとメタデータが使用されると、XlsxWriterによって作成されたファイルのバイナリ再現性が可能になります。
日付は次のように設定されます(メモリ内にないzipfile.pyの場合)。
timestamp = time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0))
os.utime(os_filename, (timestamp, timestamp))
表示されているエラーは、これが何らかの方法で失敗し、日付が1980年1月1日より前に設定されている場合に発生します。
これは、ユーザーがコンテナーを使用していて、コンテナーのホストシステムとの時間が異なる状況で、これが発生するのを1回だけ見たことがあります。
このような状況や、何らかの理由でタイムスタンプが正しく設定されていない可能性がありますか?
更新:失敗した例と同じ環境でこれを実行してみてください。
import os
import time
filename = 'file.txt'
file = open(filename, 'w')
file.close()
timestamp = time.mktime((1980, 1, 1, 0, 0, 0, 0, 0, 0))
os.utime(filename, (timestamp, timestamp))
print(time.ctime(os.path.getmtime(filename)))
# Should give:
# Tue Jan 1 00:00:00 1980
更新:この問題はXlsxWriter> = 1.1.9で修正されています。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加