我正在尝试将二进制文件上传到 postgres 服务器。我认为我正确地修改了Python脚本(https://gist.github.com/illume/8aa7c2d03273da846bf4361236a4f3f9#file-image_save-py),以便它将连接到我的postgres服务器,但我一直试图在命令行。据我了解,我需要导航到包含 image_save.py 脚本的目录并调用它。我还在同一目录中放置了一个测试文件,因此我尝试执行:
python image_save.py shuttle.jpg
Run Code Online (Sandbox Code Playgroud)
为此,我收到此错误:“错误:需要参数之一 --store --fetch 。”
然后我尝试:
python image_save.py --store shuttle.jpg
Run Code Online (Sandbox Code Playgroud)
我有:
Traceback (most recent call last):
File "image_save.py", line 45, in <module>
main(sys.argv)
File "image_save.py", line 30, in main
curs.execute("INSERT INTO files(id, orig_filename, file_data) VALUES (DEFAULT,%s,%s) RETURNING id", (args.filename, filedata))
ValueError: A string literal cannot contain NUL (0x00) characters.
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
python -m image_save.py shuttle.jpg
Run Code Online (Sandbox Code Playgroud)
我得到“C:\Python27\python.exe: 没有名为 image_save.py 的模块”
我真的认为我只是错误地调用了脚本。谁能看到我做错了什么吗?