Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError while generating from utf8 .xsd #302

Closed
Shinigami9000 opened this issue Oct 26, 2020 · 4 comments
Closed

UnicodeEncodeError while generating from utf8 .xsd #302

Shinigami9000 opened this issue Oct 26, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@Shinigami9000
Copy link

I have been trying to generate classes using your library but i ran into the following problem while trying to generate
upa_2020_response.xsd

link to the responce
https://www.sivi.org/upa_2020_response-2/

I also ran into the same problem with the following .xsd's
https://www.sivi.org/upa_2020_request-2/
https://www.sivi.org/upa_2021_response/
https://www.sivi.org/upa_2021_request-2/

Could you take a look at this problem?

Hope to hear from you soon

kind regards,

Connor

`PS C:\Users\Connor.Deutz\AppData\Roaming\Python\Python38\Python_XML_Builder> xsdata .\xsd_format\upa_2020_response.xsd
Parsing schema upa_2020_response.xsd
Compiling schema upa_2020_response.xsd
Builder: 17 main and 1 inner classes
Analyzer input: 17 main and 1 inner classes
Analyzer output: 9 main and 1 inner classes
Generating package: init
Generating package: generated.upa_2020_response
Traceback (most recent call last):

File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\Connor.Deutz\AppData\Local\Programs\Python\Python38-32\Scripts\xsdata.exe_main
.py", line 7, in
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 829, in call
return self.main(*args, **kwargs)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\xsdata\cli.py", line 98, in generate
transformer.process_schemas(list(uris))
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\xsdata\codegen\transformer.py", line 68, in process_schemas
self.process_classes()
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\xsdata\codegen\transformer.py", line 91, in process_classes
writer.write(classes)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\site-packages\xsdata\codegen\writer.py", line 33, in write
result.path.write_text(result.source)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\pathlib.py", line 1252, in write_text
return f.write(data)
File "c:\users\connor.deutz\appdata\local\programs\python\python38-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x80' in position 3234: character maps to
PS C:\Users\Connor.Deutz\AppData\Roaming\Python\Python38\Python_XML_Builder> `

@tefra
Copy link
Owner

tefra commented Oct 26, 2020

Hi @Shinigami9000

I see you are on windows, let me try a few tests, it seems the pathlib is not using utf-8 to write the generated code.

What is the output of

python -c 'import sys; print(sys.getdefaultencoding())'

can you try to export PYTHONIOENCODING=UTF-8 in your console and try again?

@tefra
Copy link
Owner

tefra commented Oct 26, 2020

Thanks for reporting @Shinigami9000

I managed to reproduce it.

The fix is on master 🙏

@tefra tefra added the bug Something isn't working label Oct 26, 2020
@BlietZ
Copy link

BlietZ commented Oct 27, 2020

Awesome quick response! Thanks tefra!

@Shinigami9000
Copy link
Author

Thanks for the quick response! it works. Thanks tefra :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants