ewsterrenburg / python-otrs

Pythonic interface to OTRS SOAP API
GNU General Public License v3.0
47 stars 27 forks source link

Invalid syntax on client.py #22

Closed toshiro92 closed 8 years ago

toshiro92 commented 8 years ago

Hello !

I am trying to use this program via virtualenv, but it seems the client.py does not working as the error here:

(virtualenv)[me@machine otrs]$ python otrs/otrsTry.py Traceback (most recent call last): File "otrs/otrsTry.py", line 1, in from otrs.client import GenericTicketConnector File "/home/users/me/projects/otrs/virtualenv/lib/python2.6/site-packages/otrs/client.py", line 18 d = {extract_tagname(i): i.text for i in tag.getchildren()} ------------------------------- ^ SyntaxError: invalid syntax

The piece of code I wrote is the basic of the tutorial present on README.rst

from otrs.client import GenericTicketConnector
from otrs.objects import Ticket, Article, DynamicField, Attachment

otrs_server_uri = r'http://localhost'
webservice_name = 'WebServiceConnector'
client = GenericTicketConnector(otrs_server_uri,webservice_name)
username = input("Please enter your OTRS username")
        password = getpass.getpass(stream=sys.stderr)
        client.user_session_register(username,password)
        print ('Connected !')

Note: I used Python 2.6 and also 3.5

mjducharme commented 8 years ago

Does the webservice_name match the one in OTRS for your ticket connector? The current master branch is designed only for use with GenericTicketConnectorSOAP.yml (or GenericTicketConnector.yml in older OTRS versions). If your web service name in OTRS is not either GenericTicketConnectorSOAP or GenericTicketConnector, it suggests you may have made the web service manually and it may have other settings that do not match the YAML defaults.

toshiro92 commented 8 years ago

Yes I confirm, the webservice_name is the same as into OTRS. I also re-created the GenericTicketConnector found on Web Service Configuration, but I still have the invalix syntax issue when I launch my program. Or maybe I made a mistake about the GenericTicketConnector and I did not take the correct code ?

mjducharme commented 8 years ago

In your OTRS web service debugger does OTRS return the correct data?

toshiro92 commented 8 years ago

Hum I can see a list of "Requester" made automatically with "No data provided" and "InvokerObject returned an error" (see screenshot below).

Do I need any particular thing to do with the Generic Ticket Connector ? I only used the default code present on Web Service Configuration part.

I have some doubts about this issue, I think this is more on Python side than OTRS side. An invalix syntax is mostly about the code, not the Connector , no ?

otrs_debugger

ewsterrenburg commented 8 years ago

@toshiro92 I'm afraid there might be issues on both sides.

The line that is giving the "incorrect syntax" message tries to show you the error occurring in a readable way, however does not succeed doing so. Apparently, the status of return is valid, it has some characteristics of a normal SOAPError, yet is different enough to make this function fail.

Could you please post the following:

If the nature of the actual error is clear, I could change the error handling, so that a more meaningful error is given back, so you could figure out what is going on here.

Additionally, I'd like to know what happens when you directly use the generated SOAPEnvelop with your endpoint (http://stackoverflow.com/questions/578306/simple-free-soap-client-for-testing-web-services). Please ensure that the endpoint you use is the same as being used in python-otrs.

toshiro92 commented 8 years ago

Hum that I know from Python is before it launch a program, it check if any line is correctly indented or does not have an invalid syntax. Then It launch the program. Here the issue could be the feature which is not compatible with the current Python version I use, or an issue into the code.

I commented the line 18 on client.py, but I also had the same issues on lines:

Line 303: infos = {extract_tagname(i): int(i.text) for i in elements} Line 349: infos = {extract_tagname(i): int(i.text) for i in elements}

When I commented those lines, I had the following error message:

Traceback (most recent call last): File "otrs/otrsTry.py", line in main client.user_session_register(username,password) File "/home/users/me/projects/otrs/virtualenv/lib/python2.6/site-packages/otrs/client.py", line 201, in user_session_register user_login=user) File "/home/users/me/projects/otrs/virtualenv/lib/python2.6/site-packages/otrs/client.py", line 187, in session_create Password=password) File "/home/users/me/projects/otrs/virtualenv/lib/python2.6/site-packages/otrs/client.py", line 129, in req self.endpoint, self._pack_req(xml_req_root), File "/home/users/me/projects/otrs/virtualenv/lib/python2.6/site-packages/otrs/client.py", line 176, in _pack_req return SOAP_ENVELOPPE.format(etree.tostring(element)) ValueError: zero length field name in format

EDIT:

I've tried to install again on a virtualenv with python 3.4.2 and pip, and I had the following error when install it:

(test)[me@machine test]$ pip install python-otrs Downloading/unpacking python-otrs Downloading python_otrs-0.1.0-py2.py3-none-any.whl Installing collected packages: python-otrs *\ Error compiling '/home/users/me/projects/otrs/test/build/python-otrs/otrs/client.py'... File "/home/users/me/projects/otrs/test/build/python-otrs/otrs/client.py", line 131 print self._pack_req(xml_req_root) ^ SyntaxError: invalid syntax

Successfully installed python-otrs Cleaning up...

ewsterrenburg commented 8 years ago

@toshiro92 The "{extract_tagname(i): int(i.text) for i in elements}" might be incorrect with python 2.6 (I have only used this with python 2.7 (and 3.5).

The new message is certainly correct. The line shown in indeed incorrect syntax for python 3. In fact, the version on pypi is not compatible with python 3.

ewsterrenburg commented 8 years ago

I can confirm that this line is indeed not compatible with python 2.6. You can consider the version on pypi (i.e. what is being installed by "pip install python-otrs" compatible with python 2.7 only.

The new version (to be released soon) will also be python 3 compatible.

toshiro92 commented 8 years ago

Indeed, I just changed the version to python2.7, and now it is working well, I see now the envelope when I put my credentials.

I just recommand to update the readme file about the version needed for this project :)

Thank you for your answer !

ewsterrenburg commented 8 years ago

It'll be added to the readme soon. Will close this issue for now.