English 中文(简体)
python, xmlrpc, 整洁和统一编码问题[非公开]
原标题:python, xmlrpc, tidy & unicode issues [closed]

两天来,我一直在努力处理 我所面临的一个问题。

The final goal is to migrate the content of an apple wiki server to foswiki/twiki markup.

我找到了一个 Xslt 样式表, 它能做大部分工作, 并且做得相当好, 而且很快。 我只需要把它用在 完善的( X) HTML 上, 也就是整洁的出现的地方- 苹果维基数据结构的“ content” 字符串里面有很多 HTML 标记, 但是不完整 。

使用 xmlrpc 内查, 无证苹果 API 几乎可以使用,

试图使用整洁 现在给我:

UnicodeEncodeError:  ascii  codec can t encode character u u2013  in position 121: ordinal not in range(128)

显然,我搜索了这个错误信息, 发现了一些文章, 包括这里的一些关于Stackoverflow的文章, 但他们似乎暗示这是我使用的终端的编码问题。 然而, LANG=en_US. UTF-8 在这里, 因此这不能成为我问题的原因。

我发现一篇文章暗示要除掉管理局, 但这样做,我创造了一个新的错误信息, 对我而言也没什么意义:

UnicodeDecodeError:  ascii  codec can t decode byte 0xef in position 0: ordinal not in range(128)

相关代码片断如下:

pages = {}

paths = s.groupsForSession(session_id) # paths is a list of groups that user can read on that server
for aPath in paths:
  entries = s.wiki.getEntries(session_id, aPath)
  # entries = s.search.getEntries(session_id, aPath)
  pprint.pprint(entries)

  for uid in entries:
    try:
      entry = s.wiki.getEntryWithUID(session_id, uid[ uid ])
    except Exception, e:
      print e.faultString
      raise Exception
    pages[uid[ uid ]] = entry
    pprint.pprint(  pages[uid[ uid ]][ content ])
    print(
      tidy.parseString(
        str(
          unicode(
              pages[uid[ uid ]][ content ].strip(codecs.BOM_UTF8),  utf-8 
          )
        ),
        **options
        )
      )
最佳回答

@oefe建议:

后来我又做了几个实验,我得到了我想要的东西;看来关于编码问题的信息让我抓错树了。问题的解决方案很简单。

tidy.parseString( str( pages[uid[ uid ]][ content ].encode( utf-8 ) ), **options )
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签