Error Saving geodjango PointField - 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.

Related

'TypeError at /api/chunked_upload/ Unicode-objects must be encoded before hashing' errorwhen using botocore in Django project

I have hit a dead end with this problem. My code works perfectly in development but when I deploy my project and configure DigitalOcean Spaces & S3 bucket I get the following error when uploading media:
TypeError at /api/chunked_upload/
Unicode-objects must be encoded before hashing
I'm using django-chucked-uploads and it doesn't play well with Botocore
I'm using Python 3.7
My code is taken from this demo: https://github.com/juliomalegria/django-chunked-upload-demo
Any help will be massively helpful
This library was implemented for Python 2, so there might be a couple of things that don't work out of the box with Python 3.
This issue that you're facing is one of them since files in Python 3 are read directly as Unicode (since now py3's str is py2's unicode). The md5 hashing is the part of the code triggering this exception (this line) because it doesn't expect Unicode strings.
If you have created your own model inheriting from AbstractChunkedUpload, you can override the md5 property to encode the chunks before updating the hash. See this other SO question on how to solve this specific.
Hopefully this helped!
Disclaimer: I'm the creator of this library. However, I haven't maintained it in a long time to the point that it might be no longer usable.

Why is my Django App failing on Azure with UUID invalid syntax

My Django App runs fine locally on macOS Catalina with Python 3.8.2 and Django 3.0.5. I am deploying it to Azure as WebApp from Github selecting Python 3.8.
I have provisioned the Postgres DB, the Storage Account and the WebApp. The build process is successful.
The WebApp fails at startup with:
File "/antenv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 6, in <module>
import uuid
File "/antenv/lib/python3.8/site-packages/uuid.py", line 138
if not 0 <= time_low < 1<<32L:
^
SyntaxError: invalid syntax
I have verified that the uuid package is not within my requirements.txt file.
DB environment variables are set up.
Collectstatic successfully replicated my static data.
The WebApp is running with Docker.
Any help on this greatly appreciated.
EDIT
Rebuilt virtual environment and regenerated requirements.txt file and redeployed. This solved the issue.
Don't leave uuid == 1.30 or any version in your requirements.txt. If you want to use uuid library, simply a import uuid is enough cuz it is built in python3 already. This solution works for me. I am using Python 3.9.7.
Here is my Azure error log with uuid == 1.30 included in requirements.txt. Hope this helps.
Azure log
This is python-2.x syntax. In python-2.x there were two types of integer values: int and long. long had an L suffix at the end. An int had a fixed range, long had an arbitrary range: it could represent numbers as long as there was sufficient memory.
One could specify with the L suffix that this was a long, not an int. For example in python-2.x, one can write:
>>> type(1)
<type 'int'>
>>> type(1L)
<type 'long'>
In python-3.x, the two merged together to int, and an int can represent arbitrary large numbers, so there is no need anymore for such suffix. You are thus using a library designed for python-2.x with an interpreter that interprets python-3.x.
I would advise not to use this (version of this) library. Take a look if there is a release for python-3.x, or try to find an alternative. python-2.x is no longer supported since january 1, 2020, so it is also not a good idea to keep developing on python-2.x. Furthermore python-2.x and python-3.x differ in quite a large number of areas. It is not just an "extended" language. The way map and filter work is for example different. Therefore you better do not try to "fix" this issue, since likely a new one will pop up, or even worse, is hidden under the radar.
Rebuilding virtual environment from scratch, regenerating the requirements.txt file and then redeploying resolved the issue.

Got error 'invalid UTF-8 string at offset 1' from regexp

I need help, I have tried to find the solution but until now all I have found is stuff related to regex but I think the problem might be in another place.
I have a project locally (Windows 10 --> Xampp Latest version [Apache & Mysql], I use CodeIgniter as Framework, I developed a function which searches in my database using REGEXP (I use query builder)
It works fine and everything. Here I searched for saltarín <-- Note the accent on the letter i
So now that it works I have decided to update the online website but as soon as I was testing the online project I noticed an error jumps when I search something with accented characters or in this case the letter ñ which also works locally.
I checked my database configurations, in database.php I have dbcollat set to utf8_spanish_ci and my online database and tables are set to utf8_spanish_ci too, I think this must be a server configuration but I don't have an idea of what it really could be
In case you need it this is the piece of code which uses regexp
$this->db->where("lower(secret_colum_name) REGEXP", $this->secret_hehe);
Thanks a lot for your time, I really appreciate your help.
EDIT: I forgot to mention I'm using hostinger to host my website
It's me again. It was just as I suspected it was something about the server, After some hours of research I found out that my server didn't have the same extensions and configurations, you can use php -m command to find out your local extensions so you can then enable them on your remote server which in my case I had to do by c-panel but your case could be different.
I also changed my php version in the remote server and I'm not really sure about the next thing but it might have helped.
I had a setter defined in my model which did the next thing
$this->my_var = strtolower($my_var);
I removed strtolower and after all the steps previously mentioned I reloaded my site and now it works

Which oracle jdbc driver is my coldfusion 8 install using

I'm trying to debug a curious problem where by one coldfusion 8 instance is giving me an error (numeric or value error: character to number conversion error ORA-06512: at line 1) but with exactly the same code another coldfusion 8 instance isn't throwing the same error.
They are both on 8,0,1,195765 Enterprise, both running on Windows 2003.
I can't imagine why they might be using different drivers unfortunately I can't (without a huge faf) have them point to the same database.
I can (and have) modified the code so the error is no longer occurring, but I'm now trying to figure out what was going on.
So how do I find out what oracle jdbc driver ColdFusion is using, I found this blog post:
http://rahulnarula.blogspot.co.uk/2009/04/getting-oracle-jdbc-driver-version-info.html
But that's only returning me no driver found.
If it helps both databases are using oracle 10g and both databases appear to be set up the same way (though I haven't ruled out that there maybe something there)
You could try looking inside macromedia_drivers.jar for this file:
\macromedia\jdbc\oracle\oracle.properties
It looks like it contains the build ID for the Oracle driver.
Another approach would just be to diff macromedia-drivers.jar using beyond-compare or similar. It may not tell you what version the drivers are, but it will tell you whether they are the same.
Also, does the short, initial code block in the linked article not work? That ought to return something for the Macromedia drivers.
Barny

schema in Django with sqlite

I am new to Django, i was going through this Django site for building up a basic app.
They have explained the procedure's to use either SQLITE3 , MYSQL, postgresql... I used SQLITE3 as they tell about it being a single large file which makes it easy to use initially.
The problem i am facing is to use .schema to check the database created. I checked certain sites which tell about using it. But i am getting stuck and i m confused to use it.
What i did was
$sqlite3
sqlite>.schema
sqlite>
This above code didnt work, then i came across a forum where they told to install a add_on to Mozilla fox, which didnt work to me as there was a compatibility issue. I even specified the path name where i have this database file located.
$sqlite3
sqlite> /home/ntan3/Django-1.2.3/mysite/eg_sqlite.db
which gave an error saying wrong syntax near '/' .
The thing is could successfully run
the sample application explained by
the Django site.
but i wanted to see the Database created. Please Help
could anyone guide me a proper way to do it? even a specific link is also helpful.
Thank you.
This is basic command-line stuff. You need to pass in the path to the db file when you type sqlite3:
$ sqlite3 /home/ntan3/Django-1.2.3/mysite/eg_sqlite.db