-1

I tried to create a progress bar to view progress of file transferring by using the below code.

from tqdm import tqdm
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
srv = pysftp.Connection(host=host,username=username,password=password,cnopts=cnopts)
with tqdm(unit = 'blocks', unit_scale = True, leave = False, miniters = 1, desc = 'Uploading......', total = filesize) as tqdm_instance:
    srv.put("D:\\wp-deploy.jpg","/var/www/html/wp-deploy.jpg",callback=lambda sent:tqdm_instance.update(len(sent)))

and I got this error:

TypeError: <lambda>() takes 1 positional argument but 2 were given
Harshana
  • 5,151
  • 1
  • 17
  • 27
  • It appears that the callback for the `srv` object is passed two parameters, but your callback only accepts one. Have you read the documentation for to see the requirements for the callback? That's literally what the error is telling you: your lambda takes one arguments but it is being given two. – Bryan Oakley Sep 16 '17 at 15:47
  • I figured out the error. thanks – Harshana Sep 18 '17 at 14:25

1 Answers1

2

From the docs:

  • callback (callable) – optional callback function (form: func(int, int)) that accepts the bytes transferred so far and the total bytes to be transferred
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358