Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 指定couchdb的附件编码_Python_Unicode_Couchdb - Fatal编程技术网

Python 指定couchdb的附件编码

Python 指定couchdb的附件编码,python,unicode,couchdb,Python,Unicode,Couchdb,我有以下测试脚本: # -*- coding: utf-8 -*- import os import couchdb GREEK = u'ΑΒΓΔ ΕΖΗΘ ΙΚΛΜ ΝΞΟΠ ΡΣΤΥ ΦΧΨΩ αβγδ εζηθ ικλμ νξοπ ρςτυ φχψω' # Prepare a unicode file, encoded using ENCODING ENCODING = 'utf-8' filename = '/tmp/test' open(filename, 'w').write(

我有以下测试脚本:

# -*- coding: utf-8 -*-

import os
import couchdb

GREEK = u'ΑΒΓΔ ΕΖΗΘ ΙΚΛΜ ΝΞΟΠ ΡΣΤΥ ΦΧΨΩ αβγδ εζηθ ικλμ νξοπ ρςτυ φχψω'

# Prepare a unicode file, encoded using ENCODING
ENCODING = 'utf-8'
filename = '/tmp/test'
open(filename, 'w').write(GREEK.encode(ENCODING))

# Create an empty document
server = couchdb.Server()
db = server['cdb-tests']
doc_id = 'testing'
doc = { }
db[doc_id] = doc

# Attach the file to the document
content = open(filename, 'rb') # Open the file for reading
db.put_attachment(doc, content, content_type='text/plain')
如您所见,该文件是utf-8编码的,但是当我将该文件附加到couchdb时,我无法指定这种编码。因此,在
http://localhost:5984/cdb-tests/testing/test
返回以下响应标题:

HTTP/1.1 200 OK
Server: CouchDB/1.2.0 (Erlang OTP/R15B01)
ETag: "7y85tiUeF/UX9kqpKAzQEw=="
Date: Fri, 03 Jan 2014 13:43:36 GMT
Content-Type: text/plain
Content-MD5: 7y85tiUeF/UX9kqpKAzQEw==
Content-Length: 102
Content-Encoding: gzip
Cache-Control: must-revalidate
Accept-Ranges: none

用浏览器查看附件完全是胡说八道。如何存储couchdb附件的编码?

根据couchdb邮件列表中的建议,解决方案是:

db.put_attachment(doc, content, content_type='text/plain;charset=utf-8')

正如couchdb邮件列表中所建议的,解决方案是:

db.put_attachment(doc, content, content_type='text/plain;charset=utf-8')

我没有使用过couchdb,但是您尝试过
编解码器
模块和
编解码器。打开
<代码>编解码器。打开使用类似文件的界面生成对象,并允许您指定编码。我没有使用couchdb,但您尝试过使用
编解码器
模块和
编解码器。打开
<代码>编解码器。打开使用类似文件的界面生成对象,并允许您指定编码。