Install pip in the Raspberry Pi & using requests for HTTP request via JSON

What is pip:

pipĀ is used for downloading and managing python packages/libraries.

Install pip:

Download the get-pip.py from internet:

wget "https://bootstrap.pypa.io/get-pip.py"

Run the file with sudo:

sudo python get-pip.py

What is requests:

Requests is an elegant and simple HTTP library for Python.

Install requests:

sudo pip install requests

Testing:

Create and edit a python file in Pi with

nano test.py

By the following code, we are able to make a simple GET request:

import requests

base_url = 'http://192.168.1.19:3000'
path = '/apis/hello'

r = requests.get(base_url+path)

status_code = r.status_code

json_data = r.json()

json

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s