Raspberry Pi上的SSL错误 [英] SSL error on Raspberry Pi

查看:169
本文介绍了Raspberry Pi上的SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了Raspberry Pi来运行一些Python脚本,但是当我移植它时,我编写的通过Windows Live发送电子邮件的功能在成功握手后突然开始分发SSL错误,具体是:

I recently purchased a Raspberry Pi to run some Python scripts, but when I ported it the function I wrote to send emails through Windows Live suddenly started handing out an SSL error after successful handshake, specifically:

error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

广泛搜索之后,我发现许多人有相同的错误,但都处在截然不同的情况下.我能找到的最相关的东西是,这似乎与特定版本的OpenSSL有关,但对于在我的Pi(1.0.1e)上运行的版本却一无所获.

After extensive searching around, I found many people with the same error, but all in vastly different situations. The most relevant thing I could find was that it seemed to be an issue with a specific version of OpenSSL, but I could find nothing about the version running on my Pi (1.0.1e).

该函数(在Win7上可以很好地工作):

The function (which works perfectly fine on Win7):

def wlive(adr_to, adr_fro, adr_pass, adr_subj, adr_file):

    saveout = smtplib.stderr
    logger = open('wlive.log', 'w')
    smtplib.stderr = logger

    msg = MIMEMultipart()
    msg['Subject'] = adr_subj
    msg['From'] = adr_fro
    msg['To'] = adr_to


    if adr_file != None:
    # subtype recognition based on extension
        filext = os.path.splitext(adr_file)[1]
        if filext == '.png':
            subt = 'png'
        else:
            subt = 'jpeg'

        fp = open(adr_file, 'rb')
        img = MIMEImage(fp.read(), subt)
        fp.close()
        msg.attach(img)


    try: 
        server = smtplib.SMTP('smtp.live.com', 587)
        server.set_debuglevel(1)
        server.ehlo()
        server.starttls()
        server.login(adr_fro, adr_pass)
        server.sendmail(adr_fro, adr_to, msg.as_string())
        server.quit()
        return True

    except Exception, e:
        print 'wlive exception:\n\n', str(e)
        return False

    smtplib.stderr = saveout
    logger.close()

我正在运行完全更新和升级的Raspbian"Wheezy"图像以及Python 2.7.3

I'm running the fully updated and upgraded Raspbian "Wheezy" image, and Python 2.7.3

推荐答案

我昨天遇到了此问题.尝试做的第一件事是更改您要从其发送电子邮件给其他提供商的帐户:例如,尝试使用gmail.就我而言,它立即开始工作.

I encountered this problem yesterday. First thing to try is to change the account from which you want to send an email to some other provider: try gmail, for instance. In my case it started working instantly.

如果您也是这种情况(Microsoft的错?),请尝试使用Windows Live帐户尝试另一件事(类似于注释中建议的方法):
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof

If it's also the case for you (Microsoft's fault?), try another thing with windows live account (similar to the one suggested in the comment):
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof

然后输入:
ehlo
auth login
就我而言,什么也没发生.没有答案,只读取超时.这次尝试:
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof -no_tls1_2
然后:
ehlo
auth login
我立刻得到答案.如果仍然是您的情况,那么会有一个小问题.我还没有找到指定这种参数的任何方法(防止使用哪个版本的tls).我发现,在 python 3.3中,您可以在starttls ,您应该能够在此上下文.可以在此处找到选项列表.
我必须承认,对我来说,仅使用gmail帐户比获取python 3.3更加容易(在rpi上,您拥有3.2,无法指定上下文),甚至不确定是否会有所帮助.但是,我希望这些信息能以某种方式对您有所帮助.

then type:
ehlo
auth login
In my case nothing happened. No answer, only read timeout. This time try:
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof -no_tls1_2
Then:
ehlo
auth login
I got an answer immediately. If it's still your case, there's a little problem. I haven't found any way to specify such a parameter (which versions of tls to prevent from being used). What I found is that in python 3.3 you can give an additional context argument instarttls and you should be able to define some cipher parameters in this context. List of options can be found here.
I must admit that it was easier for me to just use the gmail account than to get python 3.3 (on rpi you've got 3.2 with no possibility of specifying the context), not being even sure if it will help. However, I hope that this information helps you somehow.

这篇关于Raspberry Pi上的SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆