我的问题是,我必须编码一个字典才能进行Sofadb设计:
我有这个命令:
params = {'descending': 'true', 'startkey': 'Mexico', 'endkey': 'Mexico'}我想要这样的网址:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=%22Mexico%22&endkey=%22Mexico%22
或像这样:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey="Mexico"&endkey="Mexico"
因此,我urllib.urlencode将dict转换为查询字符串:
urllib.urlencode(params)
这回给我类似的东西:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=Mexico&endkey=Mexico
因此,这对于CouchDB是无效的URL,因为CouchDB需要在startkey和中使用双引号endkey
如果我将字典更改为以下内容:
params = {'descending': 'true', 'startkey': '"Mexico"', 'endkey': '"Mexico"'}这将返回一个有效的URL,如下所示:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=%22Mexico%22&endkey=%22Mexico%22
但是我不想在单引号内传递双引号,有没有一种方法可以返回有效的URL?
慕码人2483693
跃然一笑
largeQ
随时随地看视频慕课网APP
相关分类