Question

someone please help how do i make a request by using urllib.request? Write a function named...

someone please help

how do i make a request by using urllib.request?

Write a function named "get_response" that three string parameters representing the protocol, name of a server, and a path for an HTTP GET request in this order. Return the response of an HTTPS GET request to the url formed by these inputs. Recall that a url will follow the format
"<protocol>://<server_name>/<path>"
The response should be returned as a string

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program screenshot:

# import urllib module import urllib. request # Create a function named get-response. # This function accepts three string pa

Sample output screenshot:

Python 3.5.1 Shell Eile Edit Shell Debug Options Window Help <! doctype html> <if lt IE 7]> <html class-no-js ie6 lt-ie7 lt-

Code to copy:

# Import urllib module
import urllib.request

# Create a function named get_response.
# This function accepts three string parameters
# And return the response of an HTTPS GET
#request in the string format.
def get_response(protocol, server, path):
    # Create URL using the given inputs.       
    url = protocol + "://" + server + "/" + path

    # Create a string to store the response.
    response_in_string = ""

    # Read the response from the url.
    with urllib.request.urlopen(url) as response:       
        response_in_bytes = response.read()

        # Change the byte code to string.
        response_in_string += response_in_bytes.decode("utf-8")

    # Return string
    return response_in_string

# Test
# Call the function get_response().
# Display the response.
print(get_response("https", "www.python.org", "about"))

Add a comment
Know the answer?
Add Answer to:
someone please help how do i make a request by using urllib.request? Write a function named...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": <Number>}" where <Number> is a floating point Number. Return the value at the key "answer" as a float Recall...

  • python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": }" where is a floating point Number. Return the value at the key "answer" as a float Recall that...

  • Write a function to dump the html content, and save it in the same directory of...

    Write a function to dump the html content, and save it in the same directory of your python script. The name of the saved html file should include the current time stamp. I currently have been trying this code. But Repl.it says "ModuleNotFoundError: No module named 'urllib2'". Could someone point out what i am doing wrong and help me include the current time stamp using 'datetime'. The format for the date and time should be YYYY_MM_DD_HH_MM_SS. import urllib2 def webpagedumb(url):...

  • You shall write a very basic web server in Javascript that will run via nodejs. Your...

    You shall write a very basic web server in Javascript that will run via nodejs. Your project shall include the following line: var paul   = require('/homes/paul/HTML/CS316/p3_req.js'); Your project will accept HTTP requests via URLs in the following format:       /[a-zA-Z0-9_]*.cgi Here are the steps you must perform for .cgi URLs: 1) call http .createserver(myprocess) my process() is a function you will write to process requests from the user via their browser 2) create a mylisten() function that takes the following parameters:...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Can someone do this first function? Using python and API! API KEY:  8bb45882c0894d8c1ad25a8dcc157c09 Function name: get_movie_recommendations Parameters:...

    Can someone do this first function? Using python and API! API KEY:  8bb45882c0894d8c1ad25a8dcc157c09 Function name: get_movie_recommendations Parameters: movie_ids (list of ints) Returns: recommended movie titles (list of strings) Description: Write a function that takes in a list of movie IDs. Find the movies corresponding to the IDs. If the popularity of the movie is greater than 20, add the movie title (string) to a list. Return the list of titles. Note: Your function should be able to handle invalid movie ids....

  • can someone please help me solve these problem in c++ language and leave useful comments below...

    can someone please help me solve these problem in c++ language and leave useful comments below so i can follow along and know what i am doing /view wa New Tab CSSO IDE 15 THE DIGIT SWAP PROBLEM Write a function named swapDigitPairs() that accepts a positive integer n as an input-output parameter which is changed to a new value similar to n's but with each pair of digits swapped in order. For example: int n = 482596; int old...

  • can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...

    can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...

  • I need HELP to get the code to do these function: If I keep clicking "Generate"...

    I need HELP to get the code to do these function: If I keep clicking "Generate" multiple times, the list keeps on getting bigger. The number of rows should always be equal to the number of columns. Also make the code to show both table at the same time? Here is the code I got some far : Code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Testing</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> </head> <style> td...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT