swagger-codegen
swagger-codegen copied to clipboard
python-flask `ValueError: source code string cannot contain null bytes`
Description
I'm getting error when trying to run python -m swagger_server
(venv) bu@debian:~/repos/api/out$ python -m swagger_server
Traceback (most recent call last):
File "/usr/local/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/lib/python3.10/runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/local/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
ValueError: source code string cannot contain null bytes
when using online generator Im not getting this issue
Swagger-codegen version
2.4.32
Swagger declaration file content or url
https://raw.githubusercontent.com/gotify/server/v2.3.0/docs/spec.json
Command line used for generation
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/gotify-swagger.yaml -l python-flask -o /local/out
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
I found the issue was strange characters in init.py files:
bu@debian:~/repos/swagger_test$ cat -v ~/repos/swagger_test/out/swagger_server/__init__.py
^@^@^@^@bubba@debian:~/repos/swagger_test$
bu@debian:~/repos/swagger_test$ cat -v ~/repos/swagger_test/out/swagger_server/controllers/__init__.py
^@^@^@^@bubba@debian:~/repos/swagger_test$
each time I generate python-flask locally using cli I have to remove those characters manually
I found the issue was strange characters in init.py files:
bu@debian:~/repos/swagger_test$ cat -v ~/repos/swagger_test/out/swagger_server/__init__.py ^@^@^@^@bubba@debian:~/repos/swagger_test$ bu@debian:~/repos/swagger_test$ cat -v ~/repos/swagger_test/out/swagger_server/controllers/__init__.py ^@^@^@^@bubba@debian:~/repos/swagger_test$each time I generate python-flask locally using cli I have to remove those characters manually
Just wanted to confirm that I've had this issue too, and this was the solution. In Notepad++, you can delete these characters and correct the file.