comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

AttributeError: module 'comtypes.gen.Word' has no attribute '_Application'

Open Estevete opened this issue 5 years ago • 4 comments

`import sys import os import comtypes.client import pythoncom import uuid import requests from docx import Document import base64 from os import listdir from os.path import isfile, join import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:

bytesDoc = req.get_json().get('base')

path = '/users/echornet/pruebas/'
newFile = open(path + 'prueba.docx','wb')
newFile.write(base64.b64decode(bytesDoc))

newFile.close()
wdFormatPDF = 17

out_file = path + 'prueba.pdf'
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(newFile,ReadOnly = 1)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()

if bytesDoc:
    return func.HttpResponse("ok")
else:
    return func.HttpResponse(
         "Please pass a bytes[] on the query string or in the request body",
         status_code=400
    )

` This code is having the error above. Any idea? I'm running the python function on an env. It creates the docx file, but no conversion is done.

Estevete avatar Feb 18 '19 14:02 Estevete

@Estevete did you find solution for this issue? I'm facing the same now

maria-matviychuk avatar Apr 25 '19 13:04 maria-matviychuk

Same problem here

snoopyjc avatar May 03 '19 14:05 snoopyjc

@snoopyjc this helped me https://stackoverflow.com/a/27219913

I tried also to solve issue such way https://stackoverflow.com/a/16481091 but it didn't help me or I did something wrong.

maria-matviychuk avatar May 10 '19 14:05 maria-matviychuk

Any news? Still facing this issue.

pauldamian avatar May 06 '20 10:05 pauldamian

@Estevete @maria-matviychuk @snoopyjc @pauldamian

In the version around the time this issue was posted, each module(file) in comtypes/gen was often generated halfway through. So modules without definitions of the objects you wanted to use were created, then errors occurred when importing.

#300 made it fewer that partial files(modules) being generated.

Due to no recent activity, I will close this issue. If the issue remains, please re-open.

junkmd avatar Dec 08 '22 10:12 junkmd