Mishty
Mishty

Reputation: 11

Web Services in Python?

How to integrate the JSON Web Services/Web Api with our python Program and Program should get configuration settings at run time from configuration file

 import urllib.request
 a_url = 'http://www.w3.org/2005/Atom'
 data = urllib.request.urlopen(a_url).read()
 print(data)

I have found this code,regarding my problem.Is this the right way to do? please help me out of this.

Upvotes: 1

Views: 44

Answers (1)

Vaibhav Vishal
Vaibhav Vishal

Reputation: 7138

You can use requests, no sane person uses urllib.

  1. Install it:

    $ pip install requests
    
  2. Then use it like this:

    import requests
    a_url = 'http://www.w3.org/2005/Atom'
    response = requests.get(a_url)
    response.status_code  # 200
    response.text  # html of the webpage
    # response.json()  # only if the url responds with json data, otherwise it will throw error
    

Upvotes: 2

Related Questions