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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:49:01+00:00 2026-05-25T01:49:01+00:00

I am trying to access a REST api and need to call it with

  • 0

I am trying to access a REST api and need to call it with a line of XML for a filter condition. My apologies for providing code that others cannot access. When I execute this code, I get the error message listed below.

import urllib2
import urllib
import hashlib
import hmac
import time
import random
import base64

def MakeRequest():
  url = 'https://api01.marketingstudio.com/API/Gateway/9'
  publickey = ''
  privatekey = ''
  method = 'Query'
  nonce = random.randrange(123400, 9999999)
  age = int(time.time())
  final = str(age) + '&' + str(nonce) + '&' + method.lower() + '&' + url.lower()  

  converted = hmac.new(privatekey, final, hashlib.sha1).digest()
  authorization = 'AMS ' + publickey + ':' + base64.b64encode(converted)

  xml_string = "<list><FilterItems><FilterItem attribute='pageNumber' value='1'/></FilterItems></list>"
  form = {'XML':xml_string}
  data = urllib.urlencode(form)
  headers = {'Content-Type': 'application/xml'}
  req = urllib2.Request(url,data,headers)
  req.add_header('ams-method', method)
  req.add_header('ams-nonce', nonce)
  req.add_header('ams-age', age)
  req.add_header('Authorization', authorization)  
  r = urllib2.urlopen(req)

  print r.read()

MakeRequest();  

Here is the error message.

Data at the root level is invalid. Line 1, position 1.
   at Aprimo.REST.Core.RESTService.GetRequest(String URI, HttpRequest req)
   at Aprimo.REST.RESTHandler.GetRequest(String apiUrl, HttpContext context)
   at Aprimo.REST.RESTHandler.ProcessRequest(HttpContext context)

I think this has the correct logic and filter conditions, what should I look at to get this to work. Thanks.

Per @Mark’s suggestion I removed the urlencode for the XML string and got the following TraceBack:

Traceback (most recent call last):
  File "file.py", line 36, in <module>
    MakeRequest(); 
  File "file.py", line 32, in MakeRequest
    r = urllib2.urlopen(req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 392, in open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in _open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 370, in _call_chain
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1194, in https_open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1155, in do_open
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 801, in _send_output
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 773, in send
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 207, in sendall
TypeError: unhashable type
  • 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-25T01:49:02+00:00Added an answer on May 25, 2026 at 1:49 am

    So the problem was with the formatting of the form variable and the encoding I was trying to do. Revising the following lines gets the call to work. I did not need to specify the headers.

     xml_string = "<list><FilterItems><FilterItem attribute='pageNumber' value='1'/></FilterItems></list>"
     data = (xml_string)
     req = urllib2.Request(url,data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A consumer is trying to call my REST API from client-side code (Javascript /
I have a REST API that I am trying to access using Rails 3.0.1
I'm currently trying to access a REST API for the first time using visual
I am trying access a REST API. I can get it working in Curl/REST
I'm trying to access the REST Disqus API using the following url: http://disqus.com/api/3.0/threads/listPosts.json ?api_key=myKey
I'm trying to call the Recurly REST API using the Hammock C# library for
I am trying to build an interface that communicates with a REST API for
I'm trying to use HTTPWebRequest to access a REST service, and am having problems
I'm trying to access the Facebook API Admin.getMetrics method via jQuery. I'm correctly composing
So I'm trying to create a C# WCF REST service that is called by

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.