View using the python module of Nifty Cloud mobile backend

There seems to be a python module for ncmb ...

I heard this story at the hackathon the other day and decided to use it immediately How about the details ... http://petitviolet.hatenablog.com/entry/20141011/1413037537

pip installation

I tried the following command in How I've done it before, but it didn't work.

curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

After all, it is listed on this site

$sudo apt-get install python-pip

I was able to install pip with.

However, it cannot be installed due to a version problem ... I'll give you the Python version of Raspberry Pi in the first place

Updated Raspberry Pi version to 2.7.7

The update was done with reference to this article.

The version was upgraded by entering the following command group.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev 
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
cd ~
wget https://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz
tar -zxvf Python-2.7.7.tgz
cd Python-2.7.7
./configure
make -j 4
sudo make install

Reboot after update

sudo reboot

Check the version after rebooting

python -V

When you hit

Python 2.7.7

You can see that it is installed correctly

Reinstall pip

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

Now you are ready for pip

Installation and preparation of ncmb python module

sudo pip install py_nifty_cloud

Also, preparation for initialization (signature generation). This module seems to read the yaml file application key and client key, so prepare it. In the following form ...

nifty_cloud.yml


APPLICATION_KEY: 'your application key'
CLIENT_KEY: 'your client key'

Write to the database

Write the code for writing to the database as follows

ncmb_post.py


#import
from py_nifty_cloud.nifty_cloud_request import NiftyCloudRequest

# instanciate with yaml file contains APPLICATION KEY and CLIENT KEY
ncr = NiftyCloudRequest('./nifty_cloud.yml')
path = '/classes/TestClass'
method = 'POST'

# post a new recode
values = {'key': 'test'}
response = ncr.post(path=path, query=values)
print(response.status_code)

When executed, it will be as shown in the figure below スクリーンショット 2015-10-04 21.21.39.png

In addition, the following warning appears on the command screen.

InsecurePlatformWarning

It seems that it will come out by all means ...

Retrieving values from the database

Similarly, the code to pull out is as follows

ncmb_get.py


#import
from py_nifty_cloud.nifty_cloud_request import NiftyCloudRequest

# instanciate with yaml file contains APPLICATION KEY and CLIENT KEY
ncr = NiftyCloudRequest('./nifty_cloud.yml')
path = '/classes/TestClass'
query = {'where' : {'key': 'test'}}
method = 'GET'

# standard way to request
# get recodes which matches a query from path, with GET or POST or PUT http method
response = ncr.request(path=path, query=query, method=method)
type(response)
# >>> requests.models.Response

# show status code
print(response.status_code)
# show response as json format
print(response.json())

The result is below

200
{u'results': [{u'key': u'test', u'createDate': u'2015-10-04T12:17:49.729Z', u'updateDate': u'2015-10-04T12:17:49.730Z', u'objectId': u'mVgYUeowLXFuEQ0R', u'acl': {u'*': {u'read': True, u'write': True}}}]}

Recommended Posts

View using the python module of Nifty Cloud mobile backend
Try using the collections module (ChainMap) of python3
Try using the Python Cmd module
Pass the path of the imported python module
Check the path of the Python imported module
View the result of geometry processing in Python
Character encoding when using csv module of python 2.7.3
I tried using the Datetime module by Python
[Python] A rough understanding of the logging module
Find the geometric mean of n! Using Python
the zen of Python
Explanation of the concept of regression analysis using python Part 2
[python] Get the list of classes defined in the module
The pain of gRPC using Python. November 2019. (Personal memo)
Let's use the Python version of the Confluence API module.
Explanation of the concept of regression analysis using Python Part 1
Write data to KINTONE using the Python requests module
Explanation of the concept of regression analysis using Python Extra 1
Study from the beginning of Python Hour8: Using packages
Control smart light "Yeelight" from Python without using the cloud
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
Towards the retirement of Python2
Make the display of Python module exceptions easier to understand
Automatic update of Python module
About the ease of Python
python: Basics of using scikit-learn ①
View the contents of the queue using the RabbitMQ Management Web API
Solve the Japanese problem when using the CSV module in Python.
What is the default TLS version of the python requests module?
[Python] I tried collecting data using the API of wikipedia
Touch NoSQL with Python using the Oracle NoSQL Database Cloud Simulator
About the features of Python
2015-11-26 python> Display the function list of the module> import math> dir (math)
The Power of Pandas: Python
I tried using the python module Kwant for quantum transport calculation
[Python] I wrote the route of the typhoon on the map using folium
[Python] LINE notification of the latest information using Twitter automatic search
Operate Maya from an external Python interpreter using the rpyc module
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
Get and set the value of the dropdown menu using Python and Selenium
How to update the python version of Cloud Shell on GCP
Using TensorFlow in the cloud integrated development environment Cloud9 ~ Basics of usage ~
The story of making a module that skips mail with python
Try using FireBase Cloud Firestore in Python for the time being
Create a compatibility judgment program with the random module of python.
Test the version of the argparse module
The story of Python and the story of NaN
Image capture of firefox using python
[Python] The stumbling block of import
Removal of haze using Python detailEnhanceFilter
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
Using Cloud Storage from Python3 (Introduction)
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Implementation of desktop notifications using Python
Extract the targz file using python
View stack trace using [Python] inspect
About the basics list of Python basics
Master the weakref module in Python