将 urllib2 与 Jython 2.2 结合使用

发布于 2024-09-06 22:02:06 字数 686 浏览 8 评论 0原文

我正在使用具有内置 Jython 2.2 实例的产品。它不附带任何 Python 标准库。当我运行这个 Jython 实例时,默认路径是

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

我将 Python 2.2 中的所有 .py 模块文件添加到 ./run/Jython/Lib 目录,并且我可以导入它们。但我想使用 urllib2 并收到此错误:

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

据我所知,_socket 模块是 Python lib-dynload 库 (_socket.so) 的一部分。 Jython 可以使用这个文件吗?我尝试将其放在我的路径中,但没有效果。

Google 搜索似乎告诉我,其他人可以在 Jython 2.2 中使用 urllib 和 urllib2,但我被困住了,我也尝试过旧版和新版 Python 的模块库。

谢谢!

I'm working with a product that has a built-in Jython 2.2 instance. It comes with none of the Python standard libraries. When I run this instance of Jython, the default path is

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

I added all of the .py module files from Python 2.2 to the ./run/Jython/Lib directory, and I am able to 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 putting it in my path, but it had no effect.

A Google search seems to tell me that others are able to use urllib and urllib2 with Jython 2.2, but I'm stuck I have tried module libraries from older and newer versions of Python as well.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜空下最亮的亮点 2024-09-13 22:02:06

Andy,

我安装了干净的 Jython 2.2.1 并成功运行了以下脚本。

$ ./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 的路径中引入了一个小的修改。然而,这不是主要问题。主要问题是我刚刚意识到 Meandre 发行包中缺少 Jython 的系统模块。

复制内容

<JYTHON_HOME>/lib

您可以通过手动

<MEANDRE_HOME>/run/Jython/Lib

并重新启动服务器实例来修复它。现在默认模块应该可供基础设施的组件使用。

如果这能让你继续下去,请告诉我,我会尽快解决这个问题。

Andy,

I got a clean Jython 2.2.1 install and ran the following script successfully.

$ ./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
>>>

I went back and checked the Meandre infrastructure code base. I have found that a minor modification was introduced into the path of the embedded Jython. However, that is not the main problem. The main issue is that I just realized that the Jython's system modules are missing on the Meandre distribution bundles.

You could fix it by manually copying the contents on the

<JYTHON_HOME>/lib

to

<MEANDRE_HOME>/run/Jython/Lib

and restart the server instance. Now the default modules should be available to the components of the infrastructure.

Just let me know if that gets you going and I will work on getting that fixed soon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文