Python - calling iMatch endpoints without iMatch Anywhere

Started by ben, June 14, 2017, 07:56:36 PM

Previous topic - Next topic

ben

Hi Mario,

this is a follow up to this post (https://www.photools.com/community/index.php?topic=6710.0).

I wanted to try a python script to access iMatch.
Now, i am stuck and don't know what should work and what shouldn't.

i am running python on the same computer as iMatch 2017.6.6 (no iMatch Anywhere)

1) A simple get('http://127.0.0.1:50519/info') returns the desired information


2) When i try get('http://127.0.0.1:50519/v1/imatch/apps/info i receive an error about necessary authentication.

So, trying post('http://127.0.0.1:50519//v1/authenticate', params) returns the following error:
"message":"Too many sessions. Increase maximum session count in configuration file or install more CALS."


Question:
Does this mean i cannot call iMatch (not IMWS) endpoints from python/powershell/php/..  not even from the same computer?
Only with iMatch Anywhere?


Thanks,

Ben

Mario

The integrated web server in IMatch serves one purpose: To allow scripts / apps to run in IMatch.
I explicitly allow access from the "outside" on the same computer. This makes it possible to run, debug and analyze IMatch apps in modern web browsers, running on the same computer.
IMatch allows a maximum of 20 concurrent sessions and only connects from the local PC.


get('http://127.0.0.1:50519/v1/imatch/apps/info)

This is not an URL of an IMatch endpoint! This is the folder name of an app. You are trying to access the folder containing the info app. This cannot work.
What are you trying to achieve?

This is how an endpoint request looks:

http://127.0.0.1:50519/v1/files?id=1-100&fields=id,name&auth_token=...

The auth_token is returned when your script calls /authenticate. For the embedded IMWS you just use the Windows user name and an empty password.
Your script needs to retain the auth_token and supply it with every endpoint call. Only /info and some other endpoints don't require authentication.

See line 1888ff. in the imatchlib.js file included with IMatch.


-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ben

QuoteI explicitly allow access from the "outside" on the same computer.
Great.  ;D

It now works. I had some typos.
Now i can authenticate myself and call IMWS and iMatch endpoints.  :)

I will post a small python example when i cleaned up the code a bit.

Ben

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ben

Hi everybody,

for all of you who are interested in an alternative way of scripting ...

I attached a simple python script that calls iMatch endpoints and IMWS endpoints.
Important: There is a small section at the top, that you have to adapt to your computer -> username, port, ...

Some note:
  - The endpoint calls are run synchronously, i.e. are blocking your script!
  - You can use an OutOfTheBox python environment for a quick test: https://winpython.github.io
  - Mario created libraries for javascript that make working with the endpoint easier, e.g.: imatchlib.js
    When doing your scripts with python (or any other language) you have to do some extra work (but nothing serious)

I am not a python expert, though i tried to write the sample as easy as possible.

Enjoy! ;D


Ben

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ben

I recall there was someone asking for export possibilities to excel.

So i attached another python script that can export iMatch data to an excel table.

Excel read/write operations are done via the python library https://openpyxl.readthedocs.io/en/default/index.html

Ben