Using urllib2 with Jython 2.2

I am working with a product that has a built-in instance of Jython 2.2. It does not come with any of the standard Python libraries. When I run this instance of Jython, the default path

['./run/Jython/Lib', './run/Jython', '__classpath__']

I added all .py module files from Python 2.2 to the directory. / run / Jython / Lib and I can import them. But I want to use urllib2, and I get this error:

Traceback (innermost last):
  File "<string>", line 2, in ?
  File "./run/Jython/Lib/urllib2.py", line 90, in ?
  File "./run/Jython/Lib/socket.py", line 41, in ?
ImportError: no module named _socket

As far as I can tell, the _socket module is part of the Python lib-dynload libraries (_socket.so). Can Jython use this file? I tried to put it on my way, but it did not affect.

A google search seems to tell me that others can use urllib and urllib2 with Jython 2.2, but I'm stuck. I tried module libraries from older and newer versions of Python.

Thank!

+3
1

,

Jython 2.2.1 script.

$ ./jython
Jython 2.2.1 on java1.6.0_17
Type "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> f = urllib2.urlopen('http://www.python.org/')
>>> print f.read(100)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm
>>>

Meandre. , Jython . . , , Jython Meandre.

,

<JYTHON_HOME>/lib

to

<MEANDRE_HOME>/run/Jython/Lib

. .

, , .

+2

Source: https://habr.com/ru/post/1751821/


All Articles