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 6766763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:52:13+00:00 2026-05-26T14:52:13+00:00

import json import urllib import re import binascii def asciirepl(match): s = match.group() return

  • 0
import json
import urllib
import re
import binascii 

def asciirepl(match):
  s = match.group()  
  return binascii.unhexlify(s[2:])  

query = 'google'
p = urllib.urlopen('http://www.google.com/dictionary/json?callback=a&q='+query+'&sl=en&tl=en&restrict=pr,de&client=te')
page = p.read()[2:-10] #As its returned as a function call

#To replace hex characters with ascii characters
p = re.compile(r'\\x(\w{2})')
ascii_string = p.sub(asciirepl, page)

#Now decoding cleaned json response
data = json.loads(ascii_string)

Running it, I get this error,

shadyabhi@archlinux /tmp $ python2 define.py                                                                                                                                      
Traceback (most recent call last):
  File "define.py", line 19, in <module>
    data = json.loads(ascii_string)
  File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 1 column 403 (char 403)

As far as I think, the json is without any errors as I recieved it from google’s server. All, I did was removing hex characters. Any help would be highly appreciated.

  • 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-26T14:52:13+00:00Added an answer on May 26, 2026 at 2:52 pm

    Decoding the \x escapes may produce ” marks, which need to be re-escaped as they appear within “strings” encoded within the JSON data.

    def asciirepl(match):
      chr = binascii.unhexlify(match.group()[2:])
      return '\\' + chr if chr in ('\\"') else chr
    

    That still won’t handle control characters; so you might instead want to convert the \x escapes into \u escapes, which are described in the JSON standard and parsed by the json module. This has the side benefit of being simpler 🙂

    def asciirepl(match):
      return '\\u00' + match.group()[2:]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code: import simplejson,urllib,urllib2 query=[u'नेपाल'] urlbase=http://search.twitter.com/search.json values={'q':query[0]} data=urllib.urlencode(values) req=urllib2.Request(urlbase,data) response=urllib2.urlopen(req) json=simplejson.load(response) print json
I have noticed that some json queries, particularly in google services, return a peculiar
What is going on in the following? import json, urllib url = "funnyfurniture.net/p/10/oops-chair/" url2
how am I supposed to import json on Google App Engine? My project works
To start here is some code: import requests import json url = r'http:\\some.url' p
Here is my code. import urllib2 import urllib import json from BeautifulSoup import BeautifulSoup
currently I have the following which parses a json api.. import simplejson import urllib2
This is my code: import play.api.mvc._ import play.api.libs.json._ import play.api.libs.json.Json._ import play.api.libs.json.Writes._ class BaseController
I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
Is there a way to import data from a JSON file into R? More

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.