2015-10-19 81 views
0

我在学习Python和下面的各种在线/培训视频的早期阶段。的Python 3.4的错误 - 类型错误:“NoneType”对象不是可调用

我跑的Python 3.4.x 64位,在Windows中使用PyCharms。

在这个特殊的例子来学习如何使用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 

我抬头错误了一下,用我有限的知识,它听起来就像是一个投诉时argume nts在函数中缺少,但我不知道做什么不同,并且脚本的第一部分在测试(上载)时工作正常,这与刚刚颠倒过来并使用get而不是put的部分相同。

在此先感谢您的任何指导。

+0

当你正常运行它,什么是回溯样子? – nneonneo

+1

你有意从它自己内部调用get_file_from_server()吗?这就是你目前的缩进。 – BlivetWidget

+0

看着错误消息,它告诉你,你试图将'None'作为一个函数来调用。该行中唯一的函数调用是'reversed()'。因此,'revers'的值必须从正常的内置函数改为'None'。很明显,这发生在你的代码的其他地方。寻找它。 – kindall

回答

1

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() 
相关问题