【问题标题】:Dh Key Too Small (Python FTP) on WhonixWhonix 上的 Dh 密钥太小(Python FTP)
【发布时间】:2020-11-18 01:39:50
【问题描述】:

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

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 中尝试它时它才会失败,我不知道为什么。

这是我得到的错误,我不明白:

*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)

【问题讨论】:

    标签: python python-3.x networking ftp


    【解决方案1】:

    我刚刚花了很多时间试图找出类似的东西,并希望与您以及可能遇到此问题的任何其他人分享。

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

    正确的方法是让您连接的服务器更新他们的软件包,但是如果您和我在同一条船上并且无法控制您连接的服务器,那么另一种方法是添加 @987654323 @在你的连接之前

    请参阅下面的示例代码:

    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 向这个帖子大声喊叫,为我指明了正确的方向

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 2011-01-28
      • 2019-02-25
      相关资源
      最近更新 更多