简体   繁体   中英

Autodesk Forge - Conversion from .ipt to .stl gives error (UnicodeEncodeError)

I am working on a project to convert various file formats to .stl using a python script. Recently, I posted this question and was having problems converting from .sldprt to .stl but I was successfully able to accomplish that eventually. Right now, I am converting .fbx and .ipt files to sldprt. I am following this tutorial and in the last part, where I have to download the converted file (.stl), I get the following error:

File "3DFileConversion.py", line 224, in <module>
f.write(r.text)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-29: ordinal not in range(128)

The code is as follows:

url =  BASE_URL + 'modelderivative/v2/designdata/' + urn + '/manifest/' + OURL
headers = {
    'Authorization' : 'Bearer ' + ACCESS_TOKEN
}
try:
    with open(OUTPUT_FILE, 'w+') as f:
        r = requests.get(url, headers=headers)
        f.write(r.text)
except:
    print()
    print('Error Executing STEP 7 - Downloading error, status code:' + str(r.status_code) + ', exiting')
    raise(SystemExit(6))

print("Download Finished! Exiting")

I searched online and changed the line

f.write(r.text)

to

f.write(r.text.encode('utf8'))

Although this does remove the error and the converted files do have some data, it seems to be invalid and no CAD software opens it. Can anyone tell me how to solve this problem?

I was able to convert giving commands from command line, but the python script gives an error.

Try treat the payload of the response as bytes:

f.write(r.content)

See doc here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM