首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Whonix上的Dh密钥太小(Python FTP)

Whonix上的Dh密钥太小(Python FTP)
EN

Stack Overflow用户
提问于 2020-11-18 09:39:51
回答 1查看 73关注 0票数 1

我正在尝试从Whonix操作系统中将文件上传到服务器。我能够在Whonix中使用Filezilla成功地完成这项工作,所以我不太确定为什么Python代码不能工作。

代码语言:javascript
复制
from ftplib import FTP, FTP_TLS
import os

ftp = FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('ftp.server.com', 21)
ftp.login('Username', 'Password')
item_name = 'myfile.mp4'
item_path = os.path.abspath(item_name)

fp = open(item_path, 'rb')
ftp.storbinary('STOR {}'.format(item_name), fp, 8192)
fp.close()

有人知道我应该如何修改Python代码才能在Whonix中成功上传文件吗?作为参考,当我直接从Windows中运行Python代码时,它可以正常工作。只有当我在Whonix中尝试时,它才会失败,我不知道为什么。

这是我得到的错误,我不理解它:

代码语言:javascript
复制
*get* '220-This is a private system - No anonymous login\n'
*get* '220-IPv6 connections are also welcome on this server.\n'
*get* '220 You will be disconnected after 30 minutes of inactivity.\n'
*resp* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 17 of 50 allowed.\n220-Local time is now 01:28. Server port: 21.\n220-This is a private system - No anonymous login\n220-IPv6 connections are also welcome on this server.\n220 You will be disconnected after 30 minutes of inactivity.'
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 AUTH TLS OK.\n'
*resp* '234 AUTH TLS OK.'
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    ftp.login('Username', 'Password')
  File "/usr/lib/python3.7/ftplib.py", line 749, in login
    self.auth()
  File "/usr/lib/python3.7/ftplib.py", line 761, in auth
    server_hostname=self.host)
  File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1056)
EN

回答 1

Stack Overflow用户

发布于 2021-11-03 17:31:54

我只是花了很多时间试图弄清楚一些类似的东西,并想与你分享这一点,也可能与任何其他可能遇到这一点的人分享。

您会收到[SSL: DH_KEY_TOO_SMALL] dh key too small错误,因为您也连接的服务器使用的是过时的库。

正确的方法是让你连接的服务器更新他们的包,但是,如果你和我一样,并且不能控制你连接的服务器,那么另一种选择是在连接之前添加context.set_ciphers('DEFAULT@SECLEVEL=1')

请看下面的示例和您的代码:

代码语言:javascript
复制
from ftplib import FTP, FTP_TLS
import os

ftp = FTP_TLS()
ftp.set_debuglevel(2)
ftp.context.set_ciphers('DEFAULT@SECLEVEL=1')
ftp.connect('ftp.server.com', 21)
ftp.login('Username', 'Password')
item_name = 'myfile.mp4'
item_path = os.path.abspath(item_name)

fp = open(item_path, 'rb')
ftp.storbinary('STOR {}'.format(item_name), fp, 8192)
fp.close()

https://askubuntu.com/questions/1231844/ssl-sslerror-ssl-dh-key-too-small-dh-key-too-small-ssl-c1108向这个帖子发出的呼喊,为我指明了正确的方向

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64885788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档