Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6233129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:14:35+00:00 2026-05-24T10:14:35+00:00

I would like some advice. I have encountered the following error in Python 2.6:

  • 0

I would like some advice. I have encountered the following error in Python 2.6:

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    s.Search(query)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
  return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
  verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
  return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
  return u.close()
  File "/usr/lib/python2.6/xmlrpclib.py", line 838, in close
  raise Fault(**self._stack[0])
  Fault: <Fault 1: "<type 'exceptions.TypeError'>:dictionary key must be string">

My code is serving up part of a mini search engine using Django. In Python 3 everything runs like a dream, but Django is not available for Python 3 so I need to backdate my code, which is where the problem comes from.

My code (client.py):

# -*- coding: utf-8 -*-
from __future__ import unicode_literals # This was suggested elsewhere
import xmlrpclib

s = xmlrpclib.ServerProxy('http://localhost:11210')
data = s.Search('מלאכא') # tried prefixing with 'u'
print data

My code (Server.py):

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pickle, sys, xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
from collections import defaultdict

docscores = pickle.load(open("docscores.pkl", "rb"))
print ("Everything loaded. No errors.")

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("localhost", 11210), requestHandler=RequestHandler)

server.register_introspection_functions()

def Search(query):
    results = docscores[query]
    return results

server.register_function(Search, 'Search')

# Run the server's main loop
server.serve_forever()

As you can see it’s pretty simple, but I get a ‘dictionary key must be string’ when parsing the unicode string across to the server from the client. However, the server seems quite happy and produces the following feedback, which shows it has accessed my pickled dictionary (returning a doc number and count of the ngram):

{160: 3, 417: 1, 35: 1, 133: 1, 376: 1, 193: 1, 380: 1, 363: 1, 364: 1, 126: 1, 47: 1, 145: 1, 147: 1, 382: 1, 246: 3, 121: 4, 440: 1, 441: 1, 444: 1, 280: 1}
 localhost.localdomain - - [09/Aug/2011 13:32:23] "POST /RPC2 HTTP/1.0" 200 -

If I do:
type(query)
The result is:

I’ve also tried reload(sys), prefixing u'unicode_string', u"".join(unicode_string), and query.decode(‘utf-8’)`, but still get this error, or end up with more errors relating to unicode/ascii decoding.

Does anyone have any ideas how I can get around this error? Or is there an alternative to XMLPRPCServer for serving data between a server instance and a client in Python 2.6?

Many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:14:35+00:00Added an answer on May 24, 2026 at 10:14 am

    The doc of xmlrpclib state that for a python dictionary to be marshaled through XML the keys should be strings:

    A Python dictionary. Keys must be strings, values may be any
    conformable type. Objects of user-defined classes can be passed in;
    only their dict attribute is transmitted.

    So you should change your server Search method to return a dictionary with strings as keys:

    def Search(query):
        results = docscores[query]
        # I believe results is now a dictionary in the form {<integer>: <integer>}
        return dict((str(key), value) for key, value in results.items())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like some advice on the best approach to use in the following
I just started with WPF and would like some advice with the following: I
I would like to show some hidden text in a Flex application and have
I would like to write some data to a file in Ruby. What is
I would like to write some scripts in python that do some automated changes
I would like some advice from anyone experienced with implementing something like pessimistic locking
I'm learning Clojure and would like some advice on idiomatic usage. As part of
Would like some advice from this. I got a table where I want to
I would like some advice on the best approach for transferring DB data from
I'm would like some advice on the best data persistence solution to use for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.