Pyscript弹性搜索(Elk Enterprise)连接错误
Firefox开发人员控制台(F12)Belov中的连接错误消息。如何从Pyscript客户端连接弹性云。我简单地连接pyscript cdn并在python()中导入弹性搜索库
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
- from elasticsearch import Elasticsearch
<html>
<head>
<title>Matplotlib</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- from elasticsearch import Elasticsearch
</py-env>
</head>
<body>
<py-script>
# Password for the 'elastic' user generated by Elasticsearch
ELASTIC_PASSWORD = "LKQp5hTjR6KC5zTbFtHT2V9r"
# Found in the 'Manage Deployment' page
CLOUD_ID = " "
# Create the client instance
client = Elasticsearch(
cloud_id=CLOUD_ID,
basic_auth=("elastic", ELASTIC_PASSWORD)
)
# Successful response!
client.info()
# {'name': 'instance-0000000000', 'cluster_name': ...}
</py-script>
</body>
</html>
The ErrorUncaught (in promise) PythonError: Traceback (most recent call last):
pyparsing.exceptions.ParseException: Expected string_end, found 'elasticsearch' (at char 5), (line:1, col:6)
raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'elastics'": Expected string_end
setTimeout handler*hiwire_call_bound pyodide.asm.js:14
callPyObjectKwargs pyproxy.gen.ts:360
callPyObject pyproxy.gen.ts:384
wrapper pyodide.asm.js:14
setTimeout handler*hiwire_call_bound pyodide.asm.js:14
Connection error message in firefox developer console(f12) belov. How can I connect Elastic Cloud from pyscript client. I simple connecting Pyscript CDN and importing Elastic Search library in python()
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
- from elasticsearch import Elasticsearch
<html>
<head>
<title>Matplotlib</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- from elasticsearch import Elasticsearch
</py-env>
</head>
<body>
<py-script>
# Password for the 'elastic' user generated by Elasticsearch
ELASTIC_PASSWORD = "LKQp5hTjR6KC5zTbFtHT2V9r"
# Found in the 'Manage Deployment' page
CLOUD_ID = " "
# Create the client instance
client = Elasticsearch(
cloud_id=CLOUD_ID,
basic_auth=("elastic", ELASTIC_PASSWORD)
)
# Successful response!
client.info()
# {'name': 'instance-0000000000', 'cluster_name': ...}
</py-script>
</body>
</html>
The Error
Uncaught (in promise) PythonError: Traceback (most recent call last):
pyparsing.exceptions.ParseException: Expected string_end, found 'elasticsearch' (at char 5), (line:1, col:6)
raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'elastics'": Expected string_end
setTimeout handler*hiwire_call_bound pyodide.asm.js:14
callPyObjectKwargs pyproxy.gen.ts:360
callPyObject pyproxy.gen.ts:384
wrapper pyodide.asm.js:14
setTimeout handler*hiwire_call_bound pyodide.asm.js:14
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对
&lt; py-env&gt;
的声明是不正确的。它应该看起来像这样:类似的导入弹性核管:
但是,弹性搜索不是受支持的软件包。它依赖于Python
请求
和ssl
软件包,这些软件包由浏览器支持。请求
软件包使用操作系统TCP套接字API。该API在浏览器中不可用。这不是Pyscript限制,它是所有应用程序的浏览器的安全限制。唯一的解决方案是修改弹性搜索以使用浏览器支持的API,例如获取API 。
Your declaration for
<py-env>
is incorrect. It should look like this:Import elasticsarch like this:
However, Elastic Search is not a supported package. It relies upon the Python
Requests
andssl
packages, which are supported by browsers. TheRequests
package uses the operating system TCP Socket API. That API is not available in the browser. This is not a PyScript limitation, it is a security restriction in the browser for all applications.The only solution is to modify Elastic Search to use browser-supported APIs such as the Fetch API.