我正在使用搁置模块来保存一些数据。搁置对象的键值是设置对象。
Pickling snippet:
import shelve
other_links = {
'Blue Estate The Game, 72': 'https://store.steampowered.com/account/ackgift/A5e5AB6C5050A331B?redeemer=esmcfofp%40skinsgifts.com',
'Hope Lake, 75': 'https://store.steampowered.com/account/ackgift/70E2E6Ce9F1733265?redeemer=esmcfofp%40skinsgifts.com',
'Forget Me Not: My Organic Garden, 74': 'https://store.steampowered.com/account/ackwift/A14373949D126B37?redeemer=esmcfofp%40skinsgifts.com',
'Until I Have You, 74': 'https://store.steampowered.com/account/ackgift/69030w5ECB8D0F07F?redeemer=esmcfofp%40skinsgifts.com',
'Lex Mortis, 74': 'https://store.steampowered.com/account/ackgift/2760w1D8B48EB3601?redeemer=esmcfofp%40skinsgifts.com',
'I am Bread, 72': 'https://store.steampowered.com/account/ackgift/1CEC5e2D2BEF20C41?redeemer=esmcfofp%40skinsgifts.com',
'Lumini, 72': 'https://store.steampowered.com/account/ackgift/472F108Aw0609C215?redeemer=esmcfofp%40skinsgifts.com'
}
links = shelve.open('links', writeback = True)
for key, value in other_links.items():
db_value = links.get(key)
if not db_value:
db_value = set()
db_value.add(value)
links[key] = db_value
links.close()
在几次转储之后,引发了EOFError异常:
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\shelve.py", line 111, in __getitem__
value = self.cache[key]
KeyError: 'Blue Estate The Game, 72'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "draft.py", line 161, in get_links
send_links(client)
File "draft.py", line 363, in send_links
pickle_links(links)
File "draft.py", line 288, in pickle_links
db_value = links.get(key)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\shelve.py", line 106, in get
return self[key]
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\shelve.py", line 114, in __getitem__
value = Unpickler(f).load()
EOFError: Ran out of input
以下是我在shelve数据库中使用二进制represantation得到的内容:
{b'Lumini, 72': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/885EB5D41BEE5C06?redeemer=enugkpbh%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/2E98304B098FB501?redeemer=dtwggqot%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'Until I Have You, 74': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/C891F7EDCBE76C7A?redeemer=zpuvbsbi%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/02BCC505A7540D62?redeemer=enugkpbh%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'Hope Lake, 75': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/ED73ABF9D1D20620?redeemer=zpuvbsbi%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/367AFE87AF5CFE51?redeemer=dtwggqot%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'I am Bread, 72': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/40B2AC2B9CC73520?redeemer=xvkvctwm%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/868A11AE5F5CAC39?redeemer=dtwggqot%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'Forget Me Not: My Organic Garden, 74': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/FDD9F850DDB70369?redeemer=xvkvctwm%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/A310E30EFA33FF40?redeemer=dtwggqot%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'Blue Estate The Game, 72': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/4F56053C47479926?redeemer=zpuvbsbi%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/BD574CB54CEFB36A?redeemer=xvkvctwm%40skinsgifts.comq\x03Xb\x00\x00\x00htt',
b'Lex Mortis, 74': b'\x80\x03cbuiltins\nset\nq\x00]q\x01(Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/09CCA4C8D4E57036?redeemer=xvkvctwm%40skinsgifts.comq\x02Xb\x00\x00\x00https://store.steampowered.com/account/ackgift/EA6E67E98ECDE852?redeemer=zpuvbsbi%40skinsgifts.comq\x03Xb\x00\x00\x00htt'}
我看到数据库的每个值的第三个元素都以'htt'开头,而值本身没有二进制结尾。
答案 0 :(得分:0)
到目前为止,我还没有遇到过这个错误。我认为错误可能发生在我忘记在交互式shell中关闭文件的时刻。不过,我做了一些测试,让文件保持打开状态并获取并写入一些数据 - 错误没有被提出。