Libre office configuration file bootstrap.ini corrupt - libreoffice

I am using the libreoffice-convert package to convert a Word file into PDF. But when I try to convert I get this error. How do I fix this? I have installed LibreOffice 7.0.5
Console log is showing this error:
'C:\\Program Files\\LibreOffice\\program\\soffice.exe -env:UserInstallation=file://C:\\Users\\thesa\\AppData\\Local\\Temp\\soffice-10416-bQefydwUfs2F --headless --convert-to .pdf --outdir C:\\Users\\thesa\\AppData\\Local\\Temp\\libreofficeConvert_-10416-v46bO7ljGHRe C:\\Users\\thesa\\AppData\\Local\\Temp\\libreofficeConvert_-10416-v46bO7ljGHRe\\source'

Try this, you will probably need administrator rights.
Locate and copy your orignal file, for example to "bootstrap.ini.org", in the same directory1.
Open the file and replace its contents with this, which is a copy of my file:
[Bootstrap]
InstallMode=<installmode>
ProductKey=LibreOffice 7.0
UserInstallation=$SYSUSERCONFIG/LibreOffice/4
Another option is to re-install or repair the installation.
Note 1: This copy is just in case you need to revert.

//let data = await fs.promises.readFile(path_to_excel_file);
let data = fs.readFileSync(path_to_excel_file)
let pdfFile = await libreConvert(data, '.pdf', undefined);
await fs.promises.writeFile(`${__dirname}/${docName}.pdf`, pdfFile);
res.download(`${__dirname}/${docName}.pdf`)
It will works File.
Even If don't work then follow
below step:
Add this line 14 after instalDir
const installDir = tmp.dirSync({prefix: 'soffice', unsafeCleanup: true, ...tmpOptions});
const posixInstallDir = installDir.name.split(path.sep).join(path.posix.sep);
then Replace commant
let command = `${results.soffice} --headless --convert-to ${format}`;
That's it..

-env:UserInstallation needs to be in URI form.
Note: also that you using file:// this should be file:/// see File URI scheme
-env:UserInstallation=file:///C:/Users/thesa/AppData/Local/Temp/soffice-10416-bQefydwUfs2F
>>> from pathlib import Path
>>> def get_posix(mypath) -> str:
>>> p = Path(mypath)
>>> return p.as_posix()
>>> tmp = "C:\\Users\\thesa\\AppData\\Local\\Temp\\soffice-10416-bQefydwUfs2F"
>>> get_posix(tmp)
'C:/Users/thesa/AppData/Local/Temp/soffice-10416-bQefydwUfs2F'
or
>>> from pathlib import Path
>>> tmp = Path("C:\\Users\\thesa\\AppData\\Local\\Temp\\soffice-10416-bQefydwUfs2F")
>>> tmp.as_uri()
'file:///C:/Users/thesa/AppData/Local/Temp/soffice-10416-bQefydwUfs2F'

Related

openvino could not compile blob from frozen tensorflow pb, xml or bin model

openvino 2021.1 up and running
downloaded yolov3_tiny.weights and yolov3_tiny.cfg files from https://pjreddie.com/darknet/yolo/
As suggested in this link (https://colab.research.google.com/github/luxonis/depthai-ml-training/blob/master/colab-notebooks/Easy_TinyYolov3_Object_Detector_Training_on_Custom_Data.ipynb#scrollTo=2tojp0Wd-Pdw) downloaded https://github.com/mystic123/tensorflow-yolo-v3
used convert_weights_pb.py file to convert the weights and cfg file to a frozen yolov3 tiny .pb model.
python3 convert_weights_pb.py --class_names /home/user/depthai-python/my_job/coco.names --data_format NHWC --weights_file /home/user/depthai-python/my_job/yolov3-tiny.weights --tiny
used openvino mo.py file to convert yolov3_tiny .pb model to IR files .xml and .bin
python3 mo.py --input_model /home/user/depthai-python/my_job/frozen_darknet_yolov3_model.pb --tensorflow_use_custom_operations_config /home/user/depthai-python/my_job/yolo_v3_tiny.json --batch 1 --data_type FP16 --reverse_input_channel --output_dir /home/user/depthai-python/my_job
used this script as a python file to convert .xml and .bin to .blob file
blob_dir = "./my_job/"
binfile = "./my_job/frozen_darknet_yolov3_model.bin"
xmlfile = "./my_job/frozen_darknet_yolov3_model.xml"
import requests
url = "http://69.164.214.171:8083/compile" # change if running against other URL
payload = {
'compiler_params': '-ip U8 -VPU_NUMBER_OF_SHAVES 8 -VPU_NUMBER_OF_CMX_SLICES 8',
'compile_type': 'myriad'
}
files = {
'definition': open(xmlfile, 'rb'),
'weights': open(binfile, 'rb')
}
params = {
'version': '2021.1', # OpenVINO version, can be "2021.1", "2020.4", "2020.3", "2020.2", "2020.1", "2019.R3"
}
response = requests.post(url, data=payload, files=files, params=params)
print(response.headers)
print(response.content)
blobnameraw = response.headers.get('Content-Disposition')
print('blobnameraw',blobnameraw)
blobname = blobnameraw[blobnameraw.find('='):][1:]
with open(blob_dir + blobname, 'wb') as f:
f.write(response.content)
got the following error
{'Content-Type': 'application/json', 'Content-Length': '564', 'Server': 'Werkzeug/1.0.0 Python/3.6.9', 'Date': 'Fri, 09 Apr 2021 00:25:33 GMT'}
b'{"exit_code":1,"message":"Command failed with exit code 1, command: /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/myriad_compile -m /tmp/blobconverter/b9ea1f9cdb2c44bcb9bb2676ff414bf3/frozen_darknet_yolov3_model.xml -o /tmp/blobconverter/b9ea1f9cdb2c44bcb9bb2676ff414bf3/frozen_darknet_yolov3_model.blob -ip U8 -VPU_NUMBER_OF_SHAVES 8 -VPU_NUMBER_OF_CMX_SLICES 8","stderr":"stoi\n","stdout":"Inference Engine: \n\tAPI version ............ 2.1\n\tBuild .................. 2021.1.0-1237-bece22ac675-releases/2021/1\n\tDescription ....... API\n"}\n'
blobnameraw None
Traceback (most recent call last):
File "converter.py", line 29, in
blobname = blobnameraw[blobnameraw.find('='):][1:]
AttributeError: 'NoneType' object has no attribute 'find'
Alternatively i have tried the online blob converter tool from openvino http://69.164.214.171:8083/ gives the error for both .xm and .bin to .blob or from .pb to .blob
Anyone have idea.. i have tried all versions of openvino
We recommend you to use the myriad_compile.exe or compile_tool to convert your model to blob. Compile tool is a C++ application that enables you to compile a network for inference on a specific device and export it to a binary file. With the Compile Tool, you can compile a network using supported Inference Engine plugins on a machine that doesn't have the physical device connected and then transfer a generated file to any machine with the target inference device available.

ERROR: blob.download_to_filename, return an empty file and raise error

I'm trying to download the *.tflite model on Google Cloud Storage to my Rapberry Pi 3B+ using the code as follows:
export_metadata = response.metadata
export_directory = export_metadata.export_model_details.output_info.gcs_output_directory
model_dir_remote = export_directory + remote_model_filename # file path on Google Cloud Storage
model_dir = os.path.join("models", model_filename) # file path supposed to store locally
blob = bucket.blob(model_dir_remote)
blob.download_to_filename(model_dir)
However, this returns an empty file in my target directory locally, and meanwhile, raise an error:
# ERROR: google.resumable_media.common.InvalidResponse: ('Request failed with status code', 404,
# 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
# ERROR: google.api_core.exceptions.NotFound: 404
# GET https://storage.googleapis.com/download/storage/v1/b/ao-example/o/
# gs%3A%2F%2Fao-example%2Fmodel-export%2Ficn%2Fedgetpu_tflite-Test_Model12-2020-11-16T07%3A54%3A27.187Z%2Fedgetpu_model.tflite?alt=media:
# ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
I guaranteed the corresponding authority to the service account. What confuses me is that when I use gsutil command, it works:
gsutil cp gs://ao-example/model-export/icn/edgetpu_model.tflite models/
Is anyone encountering the same problem? Is there any error in my code? Your help will be greatly appreciated!
I used the following code:
from google.cloud import storage
from google.cloud import automl
from google.cloud.storage import Blob
client = storage.Client(project="semesterproject-294707")
bucket_name = 'ao-example'
bucket = client.get_bucket(bucket_name)
model_dir_remote = "gs://ao-example/model-export/icn/edgetpu_tflite-Test_Model13-2020-11-18T15:03:42.620Z/edgetpu_model.tflite"
blob = Blob(model_dir_remote, bucket)
with open("models/edgetpu_model13.tflite", "wb") as file_obj:
blob.download_to_file(file_obj)
This raises the same error, and return an empty file also... Still, I can use gsutil cp command to download the file...
(Edited on 06/12/2020)
The info of model generated:
export_model_details {
output_info {
gcs_output_directory: "gs://ao-example/model-export/icn/edgetpu_tflite-gc14-2020-12-06T14:43:18.772911Z/"
}
}
model_gcs_path: 'gs://ao-example/model-export/icn/edgetpu_tflite-gc14-2020-12-06T14:43:18.772911Z/edgetpu_model.tflite'
model_local_path: 'models/edgetpu_model.tflite'
It still encounters the error:
google.api_core.exceptions.NotFound: 404 GET https://storage.googleapis.com/download/storage/v1/b/ao-example/o/gs%3A%2F%2Fao-example%2Fmodel-export%2Ficn%2Fedgetpu_tflite-gc14-2020-12-06T14%3A43%3A18.772911Z%2Fedgetpu_model.tflite?alt=media: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
Still, when I use gsutil cp command, it works:
gsutil cp model_gcs_path model_local_path
Edited on 12/12/2020
Soni Sol's method works! Thanks!!
I believe you should use something like this:
from google.cloud.storage import Blob
client = storage.Client(project="my-project")
bucket = client.get_bucket("my-bucket")
blob = Blob("file_on_gcs", bucket)
with open("/tmp/file_on_premise", "wb") as file_obj:
blob.download_to_file(file_obj)
Blobs / Objects
When using the client libraries the gs:// is not needed, also the name of the bucket is being passed twice on This Question they had a similar issue and got corrected.
please try with the following code:
from google.cloud import storage
from google.cloud import automl
from google.cloud.storage import Blob
client = storage.Client(project="semesterproject-294707")
bucket_name = 'ao-example'
bucket = client.get_bucket(bucket_name)
model_dir_remote = "model-export/icn/edgetpu_tflite-Test_Model13-2020-11-18T15:03:42.620Z/edgetpu_model.tflite"
blob = Blob(model_dir_remote, bucket)
with open("models/edgetpu_model13.tflite", "wb") as file_obj:
blob.download_to_file(file_obj)

Python3 Win32com Copy body of an email and paste to a new excel file

I'm trying to copy paste an html table received by outlook email to a new excel spreadsheet but I get a "pywintypes.com_error." Seeking a more pythonic way to do a the equivalent of a "Control+A" on an email body and paste to a new spreadsheet.
The relevant pieces of code are:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# Select main Inbox
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
try:
for message in messages:
try:
if message.subject == 'myemailed Report':
print('Sender:' , message.sender)
print(message.subject)
mailItem = message.HTMLBody # <----Attempting to copy the body of the selected email.
# Start an instance of Excel
Xlsx = win32com.client.Dispatch("Excel.Application")
# Prevent Excel from asking questions.
Xlsx.DisplayAlerts = True # will change to False
Xlsx.Visible = True # will change to False
# Create a new Excel Workbook
workbook = Xlsx.Workbooks.Add()
ws = workbook.Sheets("Sheet1")
ws.Range('a7').select
ws.Paste(mailItem) # <--------------- Generates Error
workbook.SaveAs(mydesktop+'UpdatedSheet.xlsx')
# Quit Excel
Xlsx.Quit()
except:
x=1
except:
x=1
I get a message: Traceback (most recent call last):
File "", line 1, in
ws.Paste(mailItem)
File ">", line 3, in Paste
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Paste method of Worksheet class failed', 'xlmain11.chm', 0, -2146827284), None)
Is there a better way? Help is appreciated!
ws.Paste(mailItem) is the main part of the problem. Code should be:
ws.Paste()
However - copying the email body as if hitting "Ctrl-A" is a little more involved and there are a lot of almost answers. I managed to get the following work but I don't know why it works.
I used import pyperclip which requires pip install pyperclip, along with the following code:
import pyperclip
def copy(text):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text, win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
def paste():
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
return data
Then later on...
mailItem = message.HTMLBody
pyperclip.copy(mailItem)
# Start an instance of Excel
Xlsx = win32com.client.Dispatch("Excel.Application")
# Create a new Excel Workbook
workbook = Xlsx.Workbooks.Add()
ws = workbook.Sheets("Sheet1")
ws.Range('a1').select
ws.Paste()
ws.Range('a1').select
workbook.SaveAs(myexcel.xlsx')
I tried doing this without using pyperclip but the combination of the two def's in the beginning and the ws.Paste() worked.

Problem with connect facebookads library for extract data from Facebook with Marketing API using Python

I want to get info about ad campaign. And I start from this code to get campaign name. and I get this error :
Traceback (most recent call last):
File "C:/Users/win7/PycharmProjects/API_Facebook/dd.py", line 2, in <module>
from facebookads.adobjects.adaccount import AdAccount
File "C:\Users\win7\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebookads\adobjects\adaccount.py", line 1582
def get_insights(self, fields=None, params=None, async=False, batch=None, pending=False):
^
SyntaxError: invalid syntax
^
What is may be reason? and if you want, can give code examples how can I get more info about campaign?
Click here to view image: code and error
If you're using Python 3.7, use async_, not only async.
import os, re
path = r"path facebookads"
python_files = []
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith(".py"):
python_files.append(os.path.join(dirpath, filename))
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
if filename.endswith(".py"):
python_files.append(os.path.join(dirpath, filename))
for python_file in python_files:
with open(python_file, "r") as f:
text = f.read()
revised_text = re.sub("async", "async_", text)
with open(python_file, "w") as f:
f.write(revised_text)
They updated and renamed the library, now it's facebook_ads and async argument was renamed to is_async
Try updating facebookads:
$ pip install --upgrade facebookads
I'm using facebookads==2.11.4.
More info: https://pypi.org/project/facebookads/

environment variables using subprocess.check_output Python

I'm trying to do some basic module setups on my server using Python. Its a bit difficult as I have no access to the internet.
This is my code
import sys
import os
from subprocess import CalledProcessError, STDOUT, check_output
def run_in_path(command, dir_path, env_var=''):
env_var = os.environ["PATH"] = os.environ["PATH"] + env_var
print(env_var)
try:
p = check_output(command, cwd=dir_path, stderr=STDOUT)
except CalledProcessError as e:
sys.stderr.write(e.output.decode("utf-8"))
sys.stderr.flush()
return e.returncode
else:
return 0
def main():
requests_install = run_in_path('python setup.py build',
'D:\installed_software\python modules\kennethreitz-requests-e95e173')
SQL_install = run_in_path('python setup.py install', # install SQL module pypyodbc
'D:\installed_software\python modules\pypyodbc-1.3.3\pypyodbc-1.3.3')
setup_tools = run_in_path('python setup.py install', # install setup tools
'D:\installed_software\python modules\setuptools-17.1.1')
psycopg2 = run_in_path('easy_install psycopg2-2.6.1.win-amd64-py3.3-pg9.4.4-release', # install setup tools
'D:\installed_software\python modules', ';C:\srv_apps\Python33\Scripts\easy_install.exe')
print('setup complete')
if __name__ == "__main__":
sys.exit(main())
now it gets tricky when i start trying to use easy install. It appears my env variables are not being used by my subprocess.check_output call
File "C:\srv_apps\Python33\lib\subprocess.py", line 1110, in _execute_child
raise WindowsError(*e.args)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I don't want to have to upgrade to 3.4 where easy install is installed by default because my other modules are not supported on 3.4. My main challenge is the subprocess.check_call method does not take environment variables as an input and im wary of trying to use Popen() as I have never really got it to work successfully in the past. Any help would be greatly appreciated.
PATH should contain directories e.g., r'C:\Python33\Scripts', not files such as: r'C:\Python33\Scripts\easy_install.exe'
Don't hardcode utf-8 for an arbitrary command, you could enable text mode using universal_newlines parameter (not tested):
#!/usr/bin/env python3
import locale
import sys
from subprocess import CalledProcessError, STDOUT, check_output
def run(command, *, cwd=None, env=None):
try:
ignored = check_output(command, cwd=cwd, env=env,
stderr=STDOUT,
universal_newlines=True)
except CalledProcessError as e:
sys.stderr.write(e.output)
sys.stderr.flush()
return e.returncode
else:
return 0
Example:
import os
path_var = os.pathsep.join(os.environ.get('PATH', os.defpath), some_dir)
env = dict(os.environ, PATH=path_var)
run("some_command", cwd=some_path, env=env)
run("another_command", cwd=another_path, env=env)