Python Forum
'str' object has no attribute 'getfo' (Paramiko)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'str' object has no attribute 'getfo' (Paramiko)
#1
Hi, I use paramiko on python 3.7.1 for simple file manipulation between a Raspberry pi with SSH.
the connection work, I can open my file and I have no problem with read and write. The only one problem is 'get'
import paramiko
import os
from paramiko import sftp_handle
fortyone=41
localFile="C:\data\data.txt"
localpath="C:\data\data.txt"
remotepath="/home/pi/SiteCyberdependance/data/data.txt"
file="/home/pi/Sitecyberdependance/data/data.txt"
line=0
read = paramiko.SFTPFile.read
get = paramiko.SFTPClient.get
put = paramiko.SFTPClient.put
remove = paramiko.SFTPClient.remove


host = "41.41.41.41"
port = 22
transport = paramiko.Transport((host, port))
password = "414141"
username = "pi"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)


sftp.open("/home/pi/Sitecyberdependance/data/data.txt",mode='r+w', bufsize=-1)
self="/home/pi/Sitecyberdependance/data/data.txt"
#I dosen't think is the corect way I need to use 'self' rigth?#

# this is the line the error occur#
get(self, remotepath, localpath, callback=None) 


while fortyone==41:
    with open("C:\data\data.txt", "r") as search:
        for line in search:
            line = line.rstrip('\n')
line+1
lines = open("C:\data\data.txt").read().splitlines()
lines[1] = line
open("C:\data\data.txt",'w').write('\n'.join(lines))
remove(self, "/home/pi/Sitecyberdependance/data/data.txt")
put(localpath, remotepath, callback=None, confirm=True)
remove(self, "C:\data\data.txt")
and the error
Error:
Traceback (most recent call last): File "C:\pythonprogram\sshtest.py", line 29, in <module> get(self, remotepath, localpath, callback=None) File "C:\python\lib\site-packages\paramiko\sftp_client.py", line 802, in get size = self.getfo(remotepath, fl, callback) AttributeError: 'str' object has no attribute 'getfo'
this is it. if you can explain me brifly what 'self' do, what I need to change for resolve this problem, how I can improve my program and any mistake I have do.
Reply
#2
'self' is for classes. It is automatically given as a parameter when an instance method is called. I am not familiar with Paramiko, but it looks like get is a method of the SFTPClient class, which sftp is an instance of in your code. If so, this should work:

sftp.get(remotepath, localpath, callback = None)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
that work. thank for you reply!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,531 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,665 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 686 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,214 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,301 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,780 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  'dict_items' object has no attribute 'sort' Calli 6 4,352 Jul-29-2022, 09:19 PM
Last Post: Gribouillis
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 6,970 Jul-06-2022, 10:55 AM
Last Post: deanhystad
  AttributeError: 'numpy.int32' object has no attribute 'split' rf_kartal 6 4,196 Jun-24-2022, 08:37 AM
Last Post: Anushka00
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,721 Apr-27-2022, 09:27 AM
Last Post: Anldra12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020