here is my code:
import csv
import urllib.request
from ftplib import FTP
import os
import sys
url = 'https://dd.weather.gc.ca/hydrometric/csv/SK/hourly/SK_hourly_hydrometric.csv'
response = urllib.request.urlopen(url)
lines = [l.decode('utf-8') for l in response.readlines()]
sk = csv.reader(lines)
print("Python version")
print(sys.version)
import ftplib
session = ftplib.FTP('www.test.org','user','password')
file = open('D:/code/WaterAutomate/venv/current.csv','rt') # file to send
session.cwd('www')
session.storlines("STOR sk.csv",file) # send the file
file.close() # close file and FTP
session.quit()
here is the result
PS D:\code\WaterAutomate\venv> d:; cd ‘d:\code\WaterAutomate\venv’; & ‘c:\Python312\python.exe’ ‘c:\Users\RobMe.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/…/…\debugpy\launcher’ ‘39474’ ‘–’ ‘d:\code\WaterAutomate\venv\test.py’
Python version
3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
Traceback (most recent call last):
File “d:\code\WaterAutomate\venv\test.py”, line 20, in
session.storlines(“STOR sk.csv”,file) # send the file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “c:\Python312\Lib\ftplib.py”, line 526, in storlines
if buf[-1] in B_CRLF: buf = buf[:-1]
^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not ‘str’
PS D:\code\WaterAutomate\venv>
the file I am trying to upload is test so it should be str? What am I doing wrong?