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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题