Мои коды, как показано ниже, просто нужно pickle.dumps экземпляр ftp, но получил ошибку TypeError: an integer is required
.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import pickle
from ftplib import FTP_TLS
class FtpClient(object):
"""
Create sftp instance;then implemnet all sftp methods
"""
def __init__(self):
self.ftps = FTP_TLS()
if __name__ == '__main__':
ftps = FtpClient()
pickle_ftps = pickle.dumps(ftps)
print("pickle_ftps:", pickle_ftps)
Трассировка может выглядеть следующим образом:
Traceback (most recent call last):
File "/Users/jacksonshawn/PythonCodes/pythonlearning/python_learning_ftp_pickle_issue.py", line 19, in <module>
pickle_ftps = pickle.dumps(ftps)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 1380, in dumps
Pickler(file, protocol).dump(obj)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 425, in save_reduce
save(state)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 669, in _batch_setitems
save(v)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 731, in save_inst
save(stuff)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 669, in _batch_setitems
save(v)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/Users/jacksonshawn/anaconda2/lib/python2.7/copy_reg.py", line 71, in _reduce_ex
state = base(self)
TypeError: an integer is required
[Finished in 0.2s with exit code 1]
Может ли кто-нибудь предложить некоторые предложения?Я искал ответы в интернете, кажется, dill
модуль может решить эту проблему, но этот модуль не может быть использован в моей системе. Может кто-нибудь знать причину?