保存geodjango PointField时出错 [英] Error Saving geodjango PointField

查看:152
本文介绍了保存geodjango PointField时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有PointField属性的地理模型。一切都在本地工作,但是当我尝试在服务器上保存一个实例时,我会收到以下错误:

  django.db .utils.DatabaseError:用于编码UTF8的无效字节序列:0x00 

我挖入源文件发现价值观被不同的序列化;具体来说,在服务器上执行查询之前,该值没有被转义。看起来这个转义正在由 psycopg2.Binary.getquoted()完成,并且确实不会在服务器上返回正确的值。



在我的机器上:

 从psycopg2 import二进制
二进制('\\ \\ 0')。getquoted()#> '\\\\\000':: bytea

在服务器上: / p>

 从psycopg2导入二进制
二进制('\0')。getquoted()#> '\\000':: bytea

好的,这就解释了为什么它认为我'试图插入一个空字节。 (因为我是。)所以现在我已经足够了解Jonathan S.在 django-users组,但是像Jonathan一样,我不知道这是否是错误或配置错误。



有人可以指出我在正确的方向?



以下是有关设置的一些信息:

 我的电脑服务器
OS OSX 10.7 CentOS 5.5
Python 2.7 2.6
Django 1.3 1.3
Postgres 9.0.4 9.9.1
postgis 1.5.2 1.5.3- 2.rhel5
geos 3.3.0 3.3.0-1.rhel5


解决方案

最后设法弄清楚了。



差异,如这张票,是Postgres 9.1默认情况下 standard_conforming_strings 。这不是一个问题,真的,除了Django的适配器有一个基本上忽略它的错误。 修补程序已提交,它正在为我工​​作。



对于不愿意或无法应用修补程序或升级的用户,您可以使用此数据库适配器


I have a geo model with a PointField property. Everything works perfectly locally, but when I try to save an instance on the server, I get the following error:

django.db.utils.DatabaseError: invalid byte sequence for encoding "UTF8": 0x00

I dug into the source and found that the values are being serialized differently; specifically, that value isn't being escaped before the query is executed on the server. It looks like the escaping is being done by psycopg2.Binary.getquoted() and sure enough, it doesn't return the correct value on the server.

On my machine:

from psycopg2 import Binary
Binary('\0').getquoted() # > "'\\\\000'::bytea"

On the server:

from psycopg2 import Binary
Binary('\0').getquoted() # > "'\\000'::bytea"

Okay, that explains why it thinks I'm trying to insert a null byte. (Because I am.) So now I know enough about what's going wrong to find a similar report by Jonathan S. on the django-users group but, like Jonathan, I don't know if this is a bug or configuration error.

Can somebody point me in the right direction?

Here's some info about the setups:

          My computer      Server
OS        OSX 10.7         CentOS 5.5
Python    2.7              2.6
Django    1.3              1.3
Postgres  9.0.4            9.9.1
postgis   1.5.2            1.5.3-2.rhel5
geos      3.3.0            3.3.0-1.rhel5

解决方案

Finally managed to figure it out.

The difference, as documented in this ticket, is that Postgres 9.1 has standard_conforming_strings on by default. Which wouldn't be a problem, really, except Django's adapter has a bug that basically ignores it. A patch was submitted and it's working for me.

For those unwilling or unable to apply the patch or upgrade, you can just use this database adapter instead.

这篇关于保存geodjango PointField时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆