Pyscript弹性搜索(Elk Enterprise)连接错误

发布于 2025-02-04 00:20:38 字数 2015 浏览 2 评论 0原文

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 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

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 技术交流群。

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

发布评论

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

评论(1

久光 2025-02-11 00:20:38

您对&lt; py-env&gt;的声明是不正确的。它应该看起来像这样:

<py-env>
  elasticsearch
</py-env>

类似的导入弹性核管:

<py-script>
 from elasticsearch import Elasticsearch
 ...

但是,弹性搜索不是受支持的软件包。它依赖于Python 请求ssl软件包,这些软件包由浏览器支持。 请求软件包使用操作系统TCP套接字API。该API在浏览器中不可用。这不是Pyscript限制,它是所有应用程序的浏览器的安全限制。

唯一的解决方案是修改弹性搜索以使用浏览器支持的API,例如获取API

Your declaration for <py-env> is incorrect. It should look like this:

<py-env>
  elasticsearch
</py-env>

Import elasticsarch like this:

<py-script>
 from elasticsearch import Elasticsearch
 ...

However, Elastic Search is not a supported package. It relies upon the Python Requests and ssl packages, which are supported by browsers. The Requests 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.

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