小编R. *_*ill的帖子

sqlite3.ProgrammingError:除非使用可解释8位字节串的text_factory,否则不得使用8位字节串

在Python中使用SQLite3,我试图存储一段UTF-8 HTML代码的压缩版本.

代码如下所示:

...
c = connection.cursor()
c.execute('create table blah (cid integer primary key,html blob)')
...
c.execute('insert or ignore into blah values (?, ?)',(cid, zlib.compress(html)))
Run Code Online (Sandbox Code Playgroud)

在这一点上得到错误:

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
Run Code Online (Sandbox Code Playgroud)

如果我使用'text'而不是'blob'并且不压缩HTML片段,那么它可以很好地工作(尽管db很大).当我使用'blob'并通过Python zlib库压缩时,我收到上面的错误消息.我环顾四周,但找不到这个简单的答案.

python sqlite unicode zlib

87
推荐指数
3
解决办法
6万
查看次数

Perl:无法将"on-the-fly"数组传递给sub

strftime(),根据cpan.org:

print strftime($template, @lt);
Run Code Online (Sandbox Code Playgroud)

我只是想不出这个正确的Perl代码配方.它一直报告我调用strftime()的错误:

...
use Date::Format;
...
sub parse_date {
 if ($_[0]) {
  $_[0] =~ /(\d{4})/;
  my $y = $1;
  $_[0] =~ s/\d{4}//;
  $_[0] =~ /(\d\d)\D(\d\d)/;
  return [$2,$1,$y];
  }
 return [7,7,2010];
 }

foreach my $groupnode ($groupnodes->get_nodelist) {
    my $groupname = $xp->find('name/text()', $groupnode);
    my $entrynodes = $xp->find('entry', $groupnode);
    for my $entrynode ($entrynodes->get_nodelist) {
        ...
        my $date_added = parse_date($xp->find('date_added/text()', $entrynode));
        ...
        $groups{$groupname}{$entryname} = {...,'date_added'=>$date_added,...};
        ...
        }
    }
...

my $imday = $maxmonth <= 12 ? 0 : 1;
...

while …
Run Code Online (Sandbox Code Playgroud)

arrays perl

5
推荐指数
1
解决办法
1385
查看次数

标签 统计

arrays ×1

perl ×1

python ×1

sqlite ×1

unicode ×1

zlib ×1