drb0901500211 2012-01-29 23:50
浏览 12
已采纳

GAE数据存储查看器中的utf8错误(运行时)

I am writing a webapp with the Go runtime in GAE.

I am saving a struct which contains a string, which is the result of hashing the bytes of another string with MD5, and then encoding the hash sum bytes into a string with hex.

Here is some code:

foo := "some string"
hashedFoo := md5.New()
hashedFoo.Write([]byte(foo))
encodedFoo := hex.EncodeToString(hashedFoo.Sum()) // this is what I'm assigning to my struct, and then saving into the Datastore

This works fine, no complaints when saving or retrieving the stored entities (through code), however, when loading the Datastore Viewer, I get an error that says something like "Error fetching entities: Property Foo is corrupt in the datastore", and then there is a traceback with a bunch of references to internal GAE files and then this: "UnicodeDecodeError: 'utf8' codec can't decode byte 0x85 in position 1: unexpected code byte". This does not happen in the local development Datastore Viewer, only in the live production one.

So my questions are: what encoding does hex.EncodeToString() use? Is there a way to specify utf-8 output? Is this a GAE bug, or is it indeed a bad encoding error?

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • douqian2334 2012-01-31 03:55
    关注

    The problem was a rogue line that was casting hashedFoo.Sum() directly into a string and assigning that to encodedFoo. This produced some strings with characters not recognizable by utf-8.

    hex.EncodeToString() works fine.

    I guess this is a lesson for myself to keep my code clean and tidy :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器