Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet176/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   172   173   174   175   176   177   178   179   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Using the Requests Module


Now that we’ve created and activated our environment and installed the package that we’ll be working with for the rest of the day, we can open Jupyter Notebook.
Note If you do not have the environment activated or the requests module installed, then you will receive errors. Be sure to activate the environment, and check that the requests module is installed.
To follow along with the content for the rest of the lesson, open up Jupyter Notebook from our “python_bootcamp” folder in terminal. Once it’s open, create a new file, and rename it to “Week_10.” Next, make the first cell markdown that has a header saying:
Virtual Environments and Requests Module.” We’ll begin working underneath that cell.
CHapter 10 INtroduCtIoN to data aNalYsIs

Sending a Request


For this lesson, we’ll be requesting information from an API created by Github. Generally, APIs require a key in order to use their service; however, we’ll be using one that doesn’t require an API key. To begin, we must send a request to a specific URL, which will send a response back to us. That response will include data that we’ll be able to parse through. Write the following:

1| # sending a request and logging the response code
3| import requests
5| r = requests.get("https://api.github.com/users/Connor-SM")
7| print( r )
8| print( type( r ))

Go ahead and run the cell. In order to use requests, you must import it, which is what we do on line 3. Next, we use the get() method within the requests object in order to request information from the given URL that we pass in. The data we expect to get back will be the profile information for my Github account. Feel free to replace “Connor- SM” in the URL with your own profile username. The first print statement will output a response code. You should get back ; if you don’t, be sure to check your Internet connection. This output is letting us know that we were successful in requesting information from the Github URL. For a list of response codes and what they mean, be sure to visit w3schools2 resource. The second print statement will output the type of our variable, which is a request object. All request objects come preloaded with default methods and attributes that we can access. This will allow us to work with the data that we received.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   172   173   174   175   176   177   178   179   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish