Skip to content

Instantly share code, notes, and snippets.

@pythonjunkie
Created August 29, 2012 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonjunkie/3517184 to your computer and use it in GitHub Desktop.
Save pythonjunkie/3517184 to your computer and use it in GitHub Desktop.
Validate in app purchases from App Store
import urllib, urllib2
import simplejson as json
import datetime url = 'https://sandbox.itunes.apple.com/verifyReceipt' receipt_data = 'receipt_data' password = 'your_password'
data = { "receipt-data": receipt_data, "password": password }
headers = {'Content-Type': 'text/Json; charset=utf-8'}
dataj = json.dumps(data)
request = urllib2.Request(url, dataj, headers)
# In case you are wondering what is being sent and the format
print "request%s" % request.get_data()
# This shows the method either POST or GET (App store wants POST and not GET)
print "request type %s" % request.get_method()
start_time = datetime.datetime.now()
response = urllib2.urlopen(request)
wait_time = datetime.datetime.now() - start_time
print('Wait time for validation call: %s' % wait_time)
response_json = json.loads(response.read())
print response_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment