doniyor
doniyor

Reputation: 37886

'utf8' codec can't decode byte 0xe4 ...: invalid continuation byte in timezone

I am doing in UserProfile model this:

def repeated_times(self, test, date):
    return self.user.user_test_results.filter(taken_date__month=date.month, djangotest=test).count()

but I am getting

'utf8' codec can't decode byte 0xe4 in position 169: invalid continuation byte

because this: enter image description here

(bigger image: http://content.screencast.com/users/doniyor/folders/Jing/media/5baf8537-b48f-4194-8b71-384ec880a7b4/2015-10-23_0753.png )

what am I missing?

Upvotes: 0

Views: 16721

Answers (2)

paxdiablo
paxdiablo

Reputation: 881553

Mitteleuropa is the German term for Central Europe. Mitteleuropäische Zeit is Central European Time.

In any case, 0xe4 is indeed a UTF-8 continuation byte and it's in the wrong place for a UTF-8 string since the preceding p (0x70, 0b01110000) is not a character that can be continued since it doesn't start with a one-bit:

Mitteleurop\xe4ische Zeit

So I'm thinking that the text you have is actually not encoded as UTF-8. In fact, code point 0xe4 is shown as the ä character in the original IBM PC code page 437.

Now I'm not sure this is actually a database problem (at least with the specific table you're querying). The actual problem appears to be in your input variable which is storing the query:

SELECT    something
    FROM  somewhere
    WHERE some condition
    AND   EXTRACT('month' FROM "djtest_result"."taken_date"
            AT TIME ZONE 'Mitteleurop\xe4isch Zeit') = 10
    ...

So I'd be looking first at whatever piece of code generated that input variable to see if it's the culprit. The timezone may come from the database, or from a config item, or it may be hard-coded. What it isn't is valid UTF-8 encoding.

Upvotes: 2

doniyor
doniyor

Reputation: 37886

I had to disable USE_TZ, then it worked.

Upvotes: 1

Related Questions