简体   繁体   English

带有SSL中的简单发布请求的线程中的SSL错误

[英]SSL Error in thread with simple post request in python

I'm trying to do a simple post request, I'm using a list because I want to send all my post request at the same time using thread. 我正在尝试做一个简单的发帖请求,我正在使用一个列表,因为我想同时使用线程发送所有发帖请求。 Here is an example of an url : 这是url的示例:

            s = "https://emoncms.org/input/post.json?node="+str(test)+"&json={test_stack_overflow:0}&apikey="+str(apikey)
            list.append(threading.Thread(target=requests.post, args=([s, ])))

I was using this code maybe 3 months ago and it worked perfectly. 我大概在3个月前就使用了这段代码,它运行良好。 I wanted to get back on this project this week and I realized that I got some errors, this one particularly : 我本周想回到这个项目,我意识到我遇到了一些错误,尤其是这个错误:

Exception in thread Thread-14:

Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
  self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 94, in post
  return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
  return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
  resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
  r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 420, in send
  raise SSLError(e, request=request)
SSLError: <unprintable SSLError object>

I got an other error, ConnectionError but I think it's due to the network or because the website can't follow it's activity or is down. 我遇到另一个错误ConnectionError,但我认为这是由于网络或网站无法跟踪其活动或已关闭。 I leave you the traceback if you want : 如果需要,我可以给您回溯:

ConnectionError: ('Connection aborted.', error(101, 'Network is unreachable'))

This code is only a part of my project, the code is running every minutes and I don't know why but this issue (SSLError) comes only maybe 10 times a day. 这段代码只是我项目的一部分,代码每分钟运行一次,我不知道为什么,但是这个问题(SSLError)一天可能只会出现10次。 I got this script running on different Raspberry Pi and some have the same problem but not the same frequency, others don't have it at all. 我在不同的Raspberry Pi上运行了此脚本,有些脚本具有相同的问题,但频率不同,而其他脚本根本没有。

Any ideas on what is going ? 有什么想法吗?
Thanks in advance ! 提前致谢 !

Use verify=False in the requests method like this 在这样的请求方法中使用verify=False

import requests
url="https://emoncms.org/input/post.json?node="+str(test)+"&json={test_stack_overflow:0}&apikey="+str(apikey)
requests.post(url,verify=False)

If you are using with threads then it will be like 如果您正在使用线程,那么它将像

list.append(threading.Thread(target=requests.post, args=(url,),kwargs={"verify":False})) #**kwargs should be passed seperately.

You are getting this error because python requests tries to verify certificate for https connections so you have to override it by passing verify=False or you can also provide certificate in verify like this requests.get(url,verify="/path/to/certificate.ext") 您正在收到此错误消息,因为python请求尝试验证https连接的证书,因此您必须通过传递verify=False来覆盖它,或者您也可以像下面的requests.get(url,verify="/path/to/certificate.ext")一样在verify中提供证书requests.get(url,verify="/path/to/certificate.ext")

Also I doubt that this should be a get request because query parameters won't come in post request as of my knowledge. 我也怀疑这应该是一个获取请求,因为据我所知,查询参数不会出现在后期请求中。 So if you use GET method same verify applies there too. 因此,如果您使用GET方法,则同样的verify也适用于此。

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

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