MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Python
  • Requests

Contents

  1. Requests
    1. Installation in Slackware
    2. Sample app in pyunit

Requests

Requests is an Apache2 Licensed HTTP library, written in Python, for human beings.

http://docs.python-requests.org/en/latest/

Installation in Slackware

  • easy_install requests # python3
  • easy_install-2.7 requests

or

  • easy_install pip
  • pip install requests

Python3 test:

   1 $ python3
   2 Python 3.4.0 (default, May  9 2014, 21:04:05) 
   3 [GCC 4.7.1] on linux
   4 Type "help", "copyright", "credits" or "license" for more information.
   5 >>> import requests
   6 >>> requests.__version__
   7 '2.3.0'
   8 >>> quit()

Python 2.7 test:

   1 $ python2.7
   2 Python 2.7.3 (default, Jul  3 2012, 21:16:07) 
   3 [GCC 4.7.1] on linux2
   4 Type "help", "copyright", "credits" or "license" for more information.
   5 >>> import requests
   6 >>> requests.__version__
   7 '2.3.0'
   8 >>> quit()

Sample app in pyunit

   1 #filename: requestsTest.py
   2 #Run tests: python3 requestsTest.py
   3 import unittest
   4 import requests
   5 #import json
   6 
   7 class SimpleTestCase(unittest.TestCase):
   8     def setUp(self):
   9         self.geocodeurl='http://maps.googleapis.com/maps/api/geocode/json'
  10 
  11     def tearDown(self):
  12         pass
  13 
  14     def testCorroios(self):
  15         payload = {'address': 'Corroios', 'sensor': 'false'}
  16         r = requests.get(self.geocodeurl,params=payload)
  17         print( r.text  )
  18         self.assertEqual(True, len(r.text)>0  )
  19         objx = r.json() #json.loads(r.text)
  20         self.assertEqual('2855-117 Corroios, Portugal' , objx['results'][0]['formatted_address'] )
  21 
  22     def testAltoDoMoinho(self):
  23         payload = {'address': 'Alto do Moinho,Setubal', 'sensor': 'false'}
  24         r = requests.get(self.geocodeurl,params=payload)
  25         print( r.text  )
  26         self.assertEqual(True, len(r.text)>0  )
  27         objx = r.json() #json.loads(r.text)
  28         self.assertEqual('Alto do Moinho, 2855, Portugal' , objx['results'][0]['formatted_address'] )
  29 
  30 
  31 if __name__ == '__main__':
  32     unittest.main()
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01