简体   繁体   English

如何使用python连接到Linux端口

[英]How to use python to connect to linux port

I am now facing the problem with using python to connect to one port which requires username/password. 我现在正面临着使用python连接到需要用户名/密码的一个端口的问题。

The web URL is xxx.xxx.xxx.xxx:9200/_plugin/head/, which is for elasticsearch. 网址是xxx.xxx.xxx.xxx:9200/_plugin/head/,用于elasticsearch。 I think the administrator has set firewall for the port, when I want to log in with web browser, the web browser will require username/password, if wrong, the web page will show "authentication failed". 我认为管理员已为端口设置了防火墙,当我要使用Web浏览器登录时,Web浏览器将需要用户名/密码,如果输入错误,则Web页面将显示“身份验证失败”。 And when I use another Linux server to use query port directly with command like 当我使用另一台Linux服务器直接通过以下命令使用查询端口时

curl -XPOST 'xx.xx.xxx.x:9200/iqas_week/_search?pretty=true' -d ...

The server will also return "Authentication Required" 服务器还将返回“需要身份验证”

My plan is to use python to connect to this port and write some query for elasticsearch just like the code above. 我的计划是使用python连接到此端口,并像上面的代码一样为elasticsearch编写一些查询。 Now with encrypted port, how can I connect to that port in python? 现在有了加密端口,如何在python中连接到该端口? I have tried with paramiko, it works for port 22 but not for port 9200, is there any other way to connect to this port using python? 我尝试使用paramiko,它适用于端口22,但不适用于端口9200,是否还有其他方法可以使用python连接到此端口?

You should be able to use urllib2 to connect to the elasticsearch listener as I believe it's just an HTTP(s?) listener. 您应该可以使用urllib2连接到elasticsearch侦听器,因为我认为它只是一个HTTP(s?)侦听器。 Why not use the elasticsearch though? 为什么不使用elasticsearch呢?

https://elasticsearch-py.readthedocs.io/en/master/ https://elasticsearch-py.readthedocs.io/en/master/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM