rsteube / flik

Blue Ant CLI client on zsh steroids
MIT License
7 stars 2 forks source link

ERROR:root:Invalid XML content received (Document is empty, line 1, column 1) #12

Open fwarmuth opened 4 years ago

fwarmuth commented 4 years ago

Hey, i am forced to use BlueAnt within my company so i looked for some ways to avoid the web UI and found this repo! Lucky me i thought but: The BlueAnt instance runs with a self signed Certificate right now, so for testing purposes i disabled ssl varification by tempering the zeep client creation for example in:

//workTimeAccountingService.py
...
from zeep.transports import Transport
...

def client():
    global service
    if not 'service' in globals():
   -->transport = Transport()
   -->transport.session.verify = False
        service =  Client(config.load()['url'] + 'WorktimeAccountingService?wsdl', transport=transport)
    return service
...

It connects, but now i get:

ERROR:root:Invalid XML content received (Document is empty, line 1, column 1)

any ideas? is my URL wrong? i can find the my WebUI: at https://<MyBlueAntInstance>/psap

Regards

rsteube commented 4 years ago

Hard to say, might be a different version (this is working with 11.2.1). There is a public demo system for the android client: https://play.google.com/store/apps/details?id=proventis.blueant.mobile&hl=de.

Testen Sie die App auf unserem Demosystem:

This redirects to https://demosystem.blueant.cloud/ which is 13.1.0 and it seems to give the same error. Location of the wsdl might have changed, i could find BaseService here: https://demosystem.blueant.cloud/BaseService.wsdl

Changing ?wsdl to .wsdl in flik/client/*Service.py and removing the /blueant/services suffix in flik/common/config.py might work, but i haven't tested that yet.

fwarmuth commented 4 years ago

Thanks for the answer.! I applied the changes: btw. i am on version 13.0.0 and it seems that i can find all .wsdl's via wget:

wget  --no-check-certificate https://<MyBlueAntInstance>/BaseService.wsdl
wget  --no-check-certificate https://<MyBlueAntInstance>/HumanService.wsdl
wget  --no-check-certificate https://<MyBlueAntInstance>/MasterDataService.wsdl
wget  --no-check-certificate https://<MyBlueAntInstance>/ProjectsService.wsdl
wget  --no-check-certificate https://<MyBlueAntInstance>/WorktimeAccountingService.wsdl

So if i try to login i get the following error:

//baseService.py
...

def login():
    username = (config.load() or config.reconfigure())['username']
    password = keyring.get_password('flik', username) or getpass.getpass()

-->session = client().service.Login(username, password)<--
    storage.writeShare('sessionID', session.sessionID)
    keyring.set_password('flik', username, password)
...

with this exception:

Exception has occurred: ConnectionError
HTTPSConnectionPo ol(host='blueant', port=443): Max retries exceeded with url: /services/BaseService (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9169db5100>: Failed to establish a new connection: [Errno -2] Name or service not known'))

it seems that it tries to connect to a host and a url which are not existing... i used ripgrep to look if that is some where configured, but did find nothing :(

any further thoughts? regards

rsteube commented 4 years ago

I think think the soap:address in the xml returned is wrong (this is from the demo server):

<wsdl:service name="BaseService">
    <wsdl:port name="BaseServicePort" binding="tns:BaseBinding">
        <wsdl:documentation>This service supports login and logout to the BlueAnt system</wsdl:documentation>
        <soap:address location="http://blueant/services/BaseService"/>
    </wsdl:port>
</wsdl:service>

So it tries to reach blueant.

rsteube commented 4 years ago

https://docs.python-zeep.org/en/master/client.html#creating-new-serviceproxy-objects

crude override:

session = client().create_service('{http://blueant.axis.proventis.net/}BaseBinding', address='https://demosystem.blueant.cloud/services/BaseService').Login(username, password)

https://github.com/rsteube/flik/blob/blueant-13.1/flik/client/baseService.py#L20

fwarmuth commented 4 years ago

I think think the soap:address in the xml returned is wrong (this is from the demo server):

<wsdl:service name="BaseService">
    <wsdl:port name="BaseServicePort" binding="tns:BaseBinding">
        <wsdl:documentation>This service supports login and logout to the BlueAnt system</wsdl:documentation>
        <soap:address location="http://blueant/services/BaseService"/>
    </wsdl:port>
</wsdl:service>

So it tries to reach blueant.

Thats true, within the BaseService.wsdl file served by my blueant instance:

$ rg blueant/services                                                                                                                                                                  
BaseService.wsdl
451:                    <soap:address location="http://blueant/services/BaseService"/>

unfortunately simple overwriting it does not work for me...

# baseService.py
...
def login():
    username = (config.load() or config.reconfigure())['username']
    password = keyring.get_password('flik', username) or getpass.getpass()

    session = client().create_service('{http://blueant.axis.proventis.net/}BaseBinding', address='https://<BlueantInstance>/BaseService').Login(username, password)

    storage.writeShare('sessionID', session.sessionID)
    keyring.set_password('flik', username, password)
...

Still dies:

Exception has occurred: TransportError
Server returned response (200) with invalid XML: Invalid XML content received (Document is empty, line 1, column 1).
Content: b''
  File "<PathToFlik>/flik/flik/client/baseService.py", line 22, in login
    session = client().create_service('{http://blueant.axis.proventis.net/}BaseBinding', address='https://<BlueantInstance>/BaseService').Login(username, password)

Can it be that SOAP communication needs to be enabled some how?

UPDATE 1 I just noticed your 13.1 branch [https://github.com/rsteube/flik/tree/blueant-13.1] - implemented the changes in my modified flik version, replaced corresponding domains and added additional use of non SSL verification and "it works!" - the output is still ugly caused by the SSL warnings, and i can not use flik list

$ flik list today
ERROR:root:unsupported format string passed to NoneType.__format__

But besides that, i am able to add worktimes and autocompletion works like a charm!

Thank you so much, can i support you so by implementing a version detection for flik?

rsteube commented 4 years ago

Yes, happy to merge if you got sth. Haven't seen a version endpoint yet and the 13.1 Version always returns 200 for HEAD requests. But the old one returns 404 for https://server/BaseService.wsdl, so maybe just try to access that and fallback to the old location if it fails.

Try this for flik list: https://github.com/rsteube/flik/commit/88969b87e7ec5c461a123e4968c33963f9a7f5f5

Will do some cleanup on the 13.1 branch when i get the time.