Firefox 開發人員控制臺 (f12) 中的連接錯誤訊息 belov。如何從 pyscript 客戶端連接 Elastic Cloud。我簡單地連接 Pyscript CDN 并在 python() 中匯入 Elastic Search 庫
<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>
錯誤
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
uj5u.com熱心網友回復:
您的宣告<py-env>不正確。它應該如下所示:
<py-env>
elasticsearch
</py-env>
像這樣匯入elasticsarch:
<py-script>
from elasticsearch import Elasticsearch
...
但是,Elastic Search 不是受支持的軟體包。它依賴于瀏覽器支持的 PythonRequests和包。ssl該Requests軟體包使用作業系統 TCP Socket API。該 API 在瀏覽器中不可用。這不是 PyScript 限制,它是瀏覽器中所有應用程式的安全限制。
唯一的解決方案是修改 Elastic Search 以使用瀏覽器支持的 API,例如Fetch API。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/487533.html
上一篇:在Elasticsearch中,如何確定索引的欄位是否將doc_values設定為true?
下一篇:洗掉垂直網格線并防止高度調整
