• Register
0 votes
6.6k views

Problem :

I am very new to python. I am doing file handling for the first time. I am trying to iterate through the group of files in my folder on my local machine and upload only ones where a file names contain "Service_Areas" to the FTP site using my below code.

 Please note : I am using Python 3.6.1 32 bit, Windows 10 64 bit

upftp = FTP('ftp.ftpsite.org')
upusername = ('username')
uppassword = ('password')
upftp.login(upusername,uppassword)
upftp.cwd(upusername.upper())
upftp.cwd('2017_05_02')

for i in os.listdir('C:\FTP_testing'):
    if i.startswith("Service_Area"):
        local_path = os.path.join('C:\FTP_testing',i)
        file = open(local_path,'rb')
        upftp.storbinary("STOR " + i, open(file, 'rb'))
        file.close()
        continue
    else:
        print('nope')

upftp.quit()

However I am getting below error:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\Test1.py", line 32, in <module>
    upftp.storbinary("STOR " + str(i), open(file, 'rb'))
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader

Any suggestions how can I fix the error?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I think it has to do with your second element in the storbinary. You are trying to open the file, but it is already the pointer to your file you opened in the line file = open(local_path,'rb'). So, now you need to try to usethe upftp.storbinary("STOR " + i, file).

I hope above suggestion will help you in resolving your error.

9 7 4
38,600 points

Related questions

0 votes
1 answer 53 views
53 views
Problem : Any suggestions how can I fix the error:Typeerror: expected str, bytes or os.pathlike object, not _io.textiowrapper..
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
1 answer 957 views
957 views
Problem : I am learning to use Python. Currently I want to iterate through the files which are present in the folder on the local machine and then want to upload only those files whose file names have "Service_Areas" to the required FTP site with the use of ... rb')) TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader Please guide me in fixing my python ftp related error.
asked May 14, 2020 Martin K 6.6k points
0 votes
1 answer 7 views
7 views
Problem: Can anyone explain what this means? > Expected str, bytes or os.pathlike object, not _io.textiowrapper
asked 3 days ago ochena 23.3k points
0 votes
1 answer 413 views
413 views
Problem: i have json file named "panamaleaks50k.json" . I want to get ['text'] field from json file but it shows me following error the JSON object must be str, bytes or bytearray, not 'TextIOWrapper' this is my code with open('C:/Users/bilal butt/Desktop/PanamalEakJson.json','r') as lst: b = json.loads(lst) print(b['text'])
asked Feb 18 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: I'm a noob in programming and just started using python 3.x several days ago. Also I never proactively used this website before altough it already saved me multiple times when I was stuck.I really am not sure though, I hope that you can help me .
asked 3 days ago salim1 60.6k points
0 votes
1 answer 7 views
7 views
Problem: I'm trying to read from a JSON file and I get the error > The json object must be str, bytes or bytearray, not 'textiowrapper'
asked 5 days ago ochena 23.3k points
0 votes
1 answer 204 views
204 views
Problem: typeerror: '_io.textiowrapper' object is not subscriptable.
asked Feb 19 Dan phillip 4.8k points
0 votes
1 answer 15 views
15 views
Problem: I have the following json object I am trying to parse with python 3: customerData = { "Joe": {"visits": 1}, "Carol": {"visits": 2}, "Howard": {"visits": 3}, "Carrie": {"visits": 4} } I am using the following python code to ... (customerData): response = json.loads(customerData) I'm getting the following error: TypeError: the JSON object must be str, bytes or bytearray, not 'dict'
asked 6 days ago padma1 34.8k points
0 votes
1 answer 42 views
42 views
Problem : any expert to help me with this : Attributeerror: '_io.textiowrapper' object has no attribute 'split'..
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
2 answers 4.2K views
4.2K views
Problem : I am very new to Python. Currently I have one textfile and now I am trying to load it and then want to make the list which should contain each and every line from the text file. I have already tried to use the split() procedure. But I am facing ... I have already wasted a lot of time in understanding and finding workaround for above error.So I am looking for the quick fix on above error.
asked Apr 8, 2020 morrisBson 3.2k points