繁体   English   中英

Python 3.4错误-TypeError:“ NoneType”对象不可调用

[英]Python 3.4 error - TypeError: 'NoneType' object is not callable

我正处于学习python的早期阶段,并关注各种在线/培训视频。

我正在Windows中使用PyCharms运行Python 3.4.x x64。

在这个特定的示例中,要学习如何使用pysftp,示例脚本将首先将文件上传到服务器,然后第二部分是从服务器下载文件。

第一部分(将文件上传到服务器)工作完美。 现在该功能已被注释掉。 脚本的第二部分现在是从服务器上拉下该文件,并且脚本在哪里失败。 我使用的代码与下面的示例相同,因此我想知道我的系统是否缺少某些内容。

下面是脚本,下面是使用pdb在调试模式下运行时看到的错误:

import pysftp as sftp
#import pdb

def push_file_to_server():
    s = sftp.Connection(host='192.168.2.36',
                        username ='root',
                        password='xxxxxxx')

    local_path = "testme.txt"
    remote_path = "/home/testme.txt"
    s.put(local_path, remote_path)
    s.close()

#push_file_to_server()


#pdb.set_trace()

def get_file_from_server():
    s = sftp.Connection(host='192.168.2.36',
                        username ='root',
                        password='xxxxxxx')

    local_path = "testme.txt"
    remote_path = "/home/testme.txt"

    s.get(remote_path, local_path)
    s.close()

    get_file_from_server()

使用调试运行脚本时,这是在调试输出中看到错误的地方:

……

> c:\python34\lib\logging\__init__.py(1877)shutdown()
-> h.flush()
(Pdb) n
> c:\python34\lib\logging\__init__.py(1878)shutdown()
-> h.close()
(Pdb) n
> c:\python34\lib\logging\__init__.py(1886)shutdown()
-> h.release()
(Pdb) n
> c:\python34\lib\logging\__init__.py(1869)shutdown()
-> for wr in reversed(handlerList[:]):
(Pdb) n
--Return--
> c:\python34\lib\logging\__init__.py(1869)shutdown()->None
-> for wr in reversed(handlerList[:]):
(Pdb) n
--Call--
Exception ignored in: <function WeakSet.__init__.<locals>._remove at 0x0000000003154158>
Traceback (most recent call last):
  File "C:\Python34\lib\_weakrefset.py", line 38, in _remove
  File "C:\Python34\lib\bdb.py", line 50, in trace_dispatch
  File "C:\Python34\lib\bdb.py", line 82, in dispatch_call
  File "C:\Python34\lib\pdb.py", line 249, in user_call
  File "C:\Python34\lib\pdb.py", line 345, in interaction
  File "C:\Python34\lib\pdb.py", line 1447, in print_stack_entry
  File "C:\Python34\lib\bdb.py", line 391, in format_stack_entry
  File "<frozen importlib._bootstrap>", line 2236, in _find_and_load
  File "<frozen importlib._bootstrap>", line 265, in __enter__
TypeError: 'NoneType' object is not callable

我稍微看了一下错误,以我有限的知识,这听起来像是函数中缺少参数时的抱怨,但是我不知道该怎么做,并且脚本的第一部分在测试(上载)时可以正常工作这与刚刚反转并使用get而不是put的那部分相同。

在此先感谢您的指导。

Python是用空格分隔的,因此除非您使用的是递归函数,否则请更改

def get_file_from_server():
    s = sftp.Connection(host='192.168.2.36',
                        username ='root',
                        password='xxxxxxx')

    local_path = "testme.txt"
    remote_path = "/home/testme.txt"

    s.get(remote_path, local_path)
    s.close()

    get_file_from_server()

def get_file_from_server():
    s = sftp.Connection(host='192.168.2.36',
                        username ='root',
                        password='xxxxxxx')

    local_path = "testme.txt"
    remote_path = "/home/testme.txt"

    s.get(remote_path, local_path)
    s.close()

get_file_from_server()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM