I'm not using Jython in GeoServer myself, so far I've just suggested stuff
that should work based on what I vaguely remember about Jython and Java,
and what can find in Stack Overflow. Sometimes it's enough to just know the
right keywords :)

Note that pip in Jython 2.7.0 in Windows apparently doesn't work (mentioned
here: https://github.com/jythontools/jython/issues/83 ).  Upgrade to Jython
2.7.1 to get pip working.  Also, any time you run pip, it's worth supplying
the full path to the pip you want, to ensure you're getting the right one.

It might be worth asking the maintainer of the Geoserver/Python plugin if
just switching out the jython Jar file is enough to upgrade.

Hope this helps

D


On Wed, 6 Sep 2017 at 22:37 Alex Chen <[email protected]> wrote:

> Hi tõnis,
>
> Thank you so much for the effort to keep this thread running!
>
> I actually did the same thing by replacing jython-2.5.0.jar with
> jython-2.7.0.jar in the WEB-INF\lib directory of GeoServer installation
> directory.
>
> My question is how you manged to get "pip install requests -t
> data_dir/scripts/lib/py" work? Did you run the pip command off your native
> Python or the standalone Jython?
>
> I ran the same command ""pip install requests -t
> "C:\geoserver_data\scripts\lib\py" off my standalone Jython but it gave me
> the follow error messages:
> *Traceback (most recent call last):*
> *  File "C:\jython2.7.0\Lib\runpy.py", line 161, in _run_module_as_main*
> *    return _run_code(code, main_globals, None,*
> *  File "C:\jython2.7.0\Lib\runpy.py", line 72, in _run_code*
> *    exec code in run_globals*
> *  File "C:\jython2.7.0\bin\pip.exe\__main__.py", line 5, in <module>*
> *  File "C:\jython2.7.0\Lib\site-packages\pip\__init__.py", line 10, in
> <module>*
> *    from pip.util import get_installed_distributions, get_prog*
> *  File "C:\jython2.7.0\Lib\site-packages\pip\util.py", line 17, in
> <module>*
> *    from pip.locations import (*
> *  File "C:\jython2.7.0\Lib\site-packages\pip\locations.py", line 109, in
> <module>*
> *    build_prefix = _get_build_prefix()*
> *  File "C:\jython2.7.0\Lib\site-packages\pip\locations.py", line 90, in
> _get_build_prefix*
> *    if file_uid != os.geteuid():*
> *AttributeError: 'module' object has no attribute 'geteuid'*
>
> "easy_install -d "C:\geoserver_data\scripts\lib\py" requests" didn't work
> either.
>
> I had to run "easy_install requests" and it proved working for me! Because
> it was installed to ""C:\jython2.7.0\Lib\site-packages\", I had to manually
> copy the installed requests and its depending packages to 
> "C:\geoserver_data\scripts\lib\py"
> so that my script can import it.
>
> I am not confident to tell whether your switching is safe or of any
> resulted consequence it might possibly have. What I am guess made your
> script work on Jython-2.7.0 but failed on Jython-2.5.0 is that Jython-2.7.0
> may include the dependent packages necessary to get "requests" that
> Jython-2.5.0 does not have.
>
> Maybe Daniel has a better answer. :)
>
> Regards,
> Alex
>
>
> On Wednesday, 6 September 2017, 4:14:20 pm AEST, tõnis kärdi <
> [email protected]> wrote:
>
>
> Alex, Daniel, thank you so much for this thread. And I'm going to
> secretly hijack it with an extra question :)
>
> How is jython version switching supposed to happen (offcially)? Is it
> possible at all?
>
> What I tried was (and this is drawn upon the original question by Alex
> about using python requests) still stubbornly use non-jython pip
> install of python packages.
>
> a) Fresh GeoServer 2.11.2 stable bin on an Ubuntu box, install wps and
> python plugins
>
> b) Add data_dir/scripts/apps/hello.py as :
>
>     import requests
>
>     url = 'http://api.open-notify.org/iss-now.json'
>
>     def app(environ, start_response):
>         r = requests.get(url)
>         r.raise_for_status()
>         start_response('200 OK', [('Content-Type', 'application/json')])
>         return [r.content]
>
> c) Restart geoserver and then from commandline
>
>     $ http -a admin http://localhost:8080/geoserver/script/apps/hello
>     http: password for admin@localhost:8080:
>     HTTP/1.1 500 Server Error
>     Content-Encoding: gzip
>     Content-Type: text/plain
>     Server: Jetty(9.2.13.v20150730)
>     Transfer-Encoding: chunked
>
>     Error executing script main.py:ImportError: No module named
> requests in <script> at line number 1
>
> d) pip install requests -t data_dir/scripts/lib/py
>
> e) But this will fail again
>
>     $ http -a admin http://localhost:8080/geoserver/script/apps/hello
>     http: password for admin@localhost:8080:
>     HTTP/1.1 500 Server Error
>     Content-Encoding: gzip
>     Content-Type: text/plain
>     Server: Jetty(9.2.13.v20150730)
>     Transfer-Encoding: chunked
>
>     Error executing script main.py:SyntaxError: mismatched input 'as'
> expecting COLON in
> ...data_dir/scripts/lib/py/urllib3/connectionpool.py at line number
> 347 at column number 45
>
> f) This looks like a py syntax error for exception handling,
> connectionpool.py:347 is:
>
>         ...
>     except (SocketTimeout, BaseSSLError) as e:
>         ...
>
> g) Download latest jython standalone jar from jython homepage (v 2.7.0
> http://www.jython.org/downloads.html) and place it in
> $GEOSERVER_HOME/webapps/geoserver/WEB-INF/lib. And remove the jarfile
> packaged with GeoServer (jython-2.5.2.jar). Restart GeoServer.
>
> h) And now the script works just fine:
>
>     $ http -a admin http://localhost:8080/geoserver/script/apps/hello
>     http: password for admin@localhost:8080:
>     HTTP/1.1 200 OK
>     Content-Encoding: gzip
>     Content-Type: application/json
>     Date: Wed, 06 Sep 2017 05:53:00 GMT
>     Server: Noelios-Restlet-Engine/1.0..8
>     Transfer-Encoding: chunked
>
>     {
>       "iss_position": {
>           "latitude": "-14.3754",
>           "longitude": "-91.2309"
>       },
>       "message": "success",
>       "timestamp": 1504677179
>     }
>
> ---
>
> Is this kind of jython jar switching is ok and are there any
> known/hypothetical consequences to it?
>
> All the best,
> Tõnis
>
>
> 2017-09-06 7:45 GMT+03:00 Alex Chen <[email protected]>:
> > Thanks Daniel so much!
> >
> > I think I have an increased understanding of Jython in GeoServer. If I
> > understand it correctly, there are two options to use 3rd party
> libraries in
> > Python scripting given that both Java and Python implementations are
> > available. One is to use Jython's easy_install or pip to install the
> > packages similar to the way that the native Python equivalent does. The
> > other way is to use the Java implementation (the jar file) and copy it to
> > "... ...\geoserver\WEB-INF\lib\". Either way, we can import the library
> in a
> > Python script to be exposed as a custom App or WPS on GeoServer.
> >
> > Cheers,
> > Alex
> >
> > On Wednesday, 6 September 2017, 12:44:11 pm AEST, Daniel Baird
> > <[email protected]> wrote:
> >
> >
> > On Wed, 6 Sep 2017 at 11:01 Alex Chen <[email protected]> wrote:
> >
> > Many thanks, Daniel & Tõnis, for both of your replies!
> >
> > The GeoServer 2.11.2 uses Jython-2.5.0.jar that is saved in the
> > "WEB-INF/lib".
> >
> >
> > I haven't tried this but I'd try getting easy_install by getting the
> python
> > file from http://peak.telecommunity.com/dist/ez_setup.py, then running
> > something like:
> >
> > java -jar /whatever/path/WEB-INF/lib/Jython-2.5.0.jar ez-setup.py
> >
> > ..and doing the rest of a normal Python bootstrap into pip, but typing
> "java
> > -jar /whatever/path/WEB-INF/lib/Jython-2.5.0.jar" instead of typing
> > "python". Then remember to specify the path to Jython's verison of pip
> > whenever you run pip, wherever that is.
> >
> >
> > [...]In terms of the "requests" package, I am still having trouble
> > installing through pip or easy_install off the standalone Jython.
> >
> > C:\jython2.7.0\bin>pip install requests
> > Traceback (most recent call last):
> >  File "C:\jython2.7.0\Lib\runpy.py", line 161, in _run_module_as_main
> > [...]
> >
> >
> >    if file_uid != os.geteuid():
> >
> > AttributeError: 'module' object has no attribute 'geteuid'
> >
> >
> > Try updating pip as recommended here:
> >
> https://stackoverflow.com/questions/30530976/how-to-install-selenium2library-for-robot-framework-using-pip-jython
> >
> >
> >
> >
> > - Daniel, you mentioned that "from Jython we can use Java networking
> > libraries". Can you elaborate it in details please? How can I use 3rd
> Java
> > libs in writing a GeoServer custom app or a web processing service in
> Python
> > or JavaScript as I would like to stick with Python/JavaScript?
> >
> >
> > As long as the .class files are in your classpath, I think you can just
> use
> > import to pull in Java library classes and use them:
> > http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
> > Although if you normally write python, it's probably simpler to stick
> with
> > whatever libs you're used to.
> >
> >
> > Cheers
> > Daniel
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this 
list:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to