pjkundert / cpppo

Communications Protocol Python Parser and Originator -- EtherNet/IP CIP
https://hardconsulting.com/products/6-cpppo-enip-api
Other
328 stars 108 forks source link

ERROR TYPE modi_code= types.CodeType( *modi_args ) #85

Closed crocodile62 closed 4 years ago

crocodile62 commented 4 years ago

I get this erro from PyCharme debug and it is not importing the libray. I have no clue about it. I get the same error launching python3 -m cpppo.server.enip

I think something is wrong in my installation, somebody could help me? thanks

My environment is Mac PowerBook with Catalina and python 3.8 with PyCharme Thanks a lot for your help this is the terminal response to python3 -m cpppo.server.enip traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 184, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 110, in _get_module_details import(pkg_name) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cpppo/init.py", line 29, in from .automata import File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cpppo/automata.py", line 33, in from . import misc File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cpppo/misc.py", line 204, in change_function( __normal, co_filename=logging._srcfile ) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cpppo/misc.py", line 163, in change_function modi_code = types.CodeType( modi_args ) TypeError: an integer is required (got type bytes)

modi_code = types.CodeType( *modi_args ) TypeError: an integer is required (got type bytes)

kdorsel commented 4 years ago

I got the same error on Python 3.8.

It works fine on Python 2.7, and I imagine it also works fine on 3.7.

Python 3.8.2 (default, Feb 26 2020, 02:56:10) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cpppo.server.enip.get_attribute import proxy as plc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gastronomous/gastro/env/lib/python3.8/site-packages/cpppo/__init__.py", line 29, in <module>
    from .automata import *
  File "/home/gastronomous/gastro/env/lib/python3.8/site-packages/cpppo/automata.py", line 33, in <module>
    from . import misc
  File "/home/gastronomous/gastro/env/lib/python3.8/site-packages/cpppo/misc.py", line 204, in <module>
    change_function( __normal, co_filename=logging._srcfile )
  File "/home/gastronomous/gastro/env/lib/python3.8/site-packages/cpppo/misc.py", line 163, in change_function
    modi_code           = types.CodeType( *modi_args )
TypeError: an integer is required (got type bytes)
EarlAlnot commented 4 years ago

Got the same error and managed to solve it by adding changing line 143. Seems types.CodeType got a new attribute (at least in a 3.8.x release).

Was:

        attrs              += [ "co_kwonlyargcount" ]

Now:

        attrs              += [ "co_posonlyargcount" ,         # <-- Added
                              "co_kwonlyargcount" ] 

First time posting and not so proficient with Github, so please have mercy.

kdorsel commented 4 years ago

Awesome, that fixed it indeed. For those looking:

https://github.com/pjkundert/cpppo/blob/272327c6d3be9f523358e73683b4862f6756b5a3/misc.py#L143

pjkundert commented 4 years ago

Python 3.7/3.8 compatibility is now complete in version 4.0.5; pushed to pypi

barthelmeh commented 1 year ago

I'm still getting an error on the same line: TypeError: code() argument 13 must be str, not int Unsure how to fix this.

EarlAlnot commented 1 year ago

Possibly already solved here by @crmaxj

It seems the arguments of type.codetype have changed again. The ones you need to use depend on your version of Python.

If you don't know where your cpppo library is stored, you could run a python script with the following lines:

import cpppo
print(cpppo.__file__)

If you need further assistance, please let me know which version of python you are running.