python / python/cpython

ftplib storbinary

Offen
#124,850 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

Bug description:

There's a problem with SSL and the storbinary method. I get this error:

Error uploading yourfile.mp3: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:2685)

A YouTuber posted a fix which creates your own storbinary function and eliminates some code in the original that solves the problem. I attached the fix below. You use this function in place of the method that comes with the library.

def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
    self.voidcmd('TYPE I')
    with self.transfercmd(cmd, rest) as conn:
        while 1:
            buf = fp.read(blocksize)
            if not buf: break
            conn.sendall(buf)
            if callback: callback(buf)
    return self.voidresp()
    
    ----
    ftps = FTP_TLS()
    ftps.set_pasv(True)

      ....
    for upload in uploads:
        print(upload)
        with open(upload, 'rb') as file:  # Use 'with' to ensure the file is closed properly
            remote_filename = os.path.basename(upload)  # Get the base filename for uploading
            try:
                storbinary(ftps, f'STOR {remote_filename}', file)
            #    ftps.storbinary(f'STOR {remote_filename}', file) 

                print(f'Successfully uploaded: {remote_filename}')
            except all_errors as e:
                print(f'Error uploading {remote_filename}: {e}')
    # Connect to the server
    ftps.connect(ftps_host)
    ftps.login(user=ftps_user, passwd=ftps_password)
    ftps.prot_p()  # Switch to secure data connection

    
CPython versions tested on:

3.12

Operating systems tested on:

macOS

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei ftplib.FTP_TLS.storbinary und reproduziere den für Python 3.12 auf macOS beschriebenen SSL-Fehler beim Upload, indem du ihn mit der beigefügten Ersatzfunktion vergleichst. Es wird keine Repository-Datei oder kein Test genannt; als erledigt gilt die Aufgabe, wenn der gemeldete Upload funktioniert, ohne storbinary zu ersetzen, und das Verhalten durch Regressionstests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.