ElasticSearchTest icon indicating copy to clipboard operation
ElasticSearchTest copied to clipboard

python3网络实战爬虫第二版 ElasticSearch一系列问题

Open RuoCJ opened this issue 3 years ago • 3 comments

@Germey hello,我在您python3网络爬虫开发实战第二版中,在4.7 elasticsearch这一章学习过程中,发现一些问题,可能是因为版本更新的原因,例如:

from elasticsearch import Elasticsearch es = Elasticsearch() result = es.indices.create(index='news',ignore=400) print(result)

上面的会报错:

ValueError: Either 'hosts' or 'cloud_id' must be specified

然后,当我这么写就不报错了

from elasticsearch import Elasticsearch es = Elasticsearch(hosts='https://localhost:9200/') result = es.indices.create(index='news',ignore=400) print(result)

但是,又出现这样的错误:

elastic_transport.TlsError: TLS error caused by: TlsError(TLS error caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)))

然后,这么修改一下:

from elasticsearch import Elasticsearch es = Elasticsearch(hosts='https://localhost:9200',verify_certs=False/) result = es.indices.create(index='news',ignore=400) print(result)

就会有新的错误:

elasticsearch.AuthenticationException: AuthenticationException(401, 'security_exception', 'missing authentication credentials for REST request [/news]')

我是第一次接触elasticsearch,这些问题我没能找到解决办法,所以向您求助。 谢谢!

RuoCJ avatar Jun 10 '22 02:06 RuoCJ

我也遇到了相同的问题,请问解决了吗

Allen0845 avatar Jul 06 '22 03:07 Allen0845

我感觉可能是版本问题,我的案例是 Elasticsearch 7.0 的,请尝试安装 7.0 版本和对应的 Python eleasticsearch 库

Germey avatar Jul 10 '22 15:07 Germey

我感觉可能是版本问题,我的案例是 Elasticsearch 7.0 的,请尝试安装 7.0 版本和对应的 Python eleasticsearch 库

好的 谢谢 我尝试一下

RuoCJ avatar Jul 10 '22 21:07 RuoCJ