CMPUT 404

Web Applications and Architecture

Virtualenv & cURL


Virtualenv & Curl Lab

Introduction to CMPUT 404 labs. Setup virtualenv and understand basic usage of curl.

Answers to the questions should be submitted to Virtualenv Lab on eClass.

Git and GitHub

  1. Make a GitHub account or log in to your existing GitHub account.

    • Question 1: What is your GitHub URL?

Command-line Environment

virtualenv

  1. Create a new directory for this lab (mkdir).
  2. cd into the created directory and initialize a new git repository (git init).
  3. Make a Python script that prints out the version of the requests library.

    • Question 2: What version is the requests library installed on the system? Is there none at all? Or is it already installed?
  4. Create a virtualenv.

    virtualenv venv --python=python3

  5. Activate the python virtual environment.

    source venv/bin/activate

  6. Try installing requests into your virtual environment.

  7. Run your Python script that prints out the version of the requests library in your virtualenv.

    • Question 3: Is requests installed? If so, what version is the requests library installed in the virtualenv?
  8. Open a new terminal.

  9. Run the script in your new terminal.

    • Question 4: What is the difference between the virtual environment and the not virtual environment python?
curl
  1. Use curl to get the Google homepage: http://google.com/
  2. This time, use curl -i to get the Google homepage.

    • Question 5: What status code is returned for http://google.com ? What URL must you visit to get a 200 status code?
  3. Curl the Google home page with -iL and examine the headers.

  4. Curl the Google Teapot page: https://www.google.com/teapot

    • Question 6: What status code is returned for http://google.com/teapot? Is it the one returned by curl -i or curl -iL? What happens when you curl http://www.google.com/teapot?
  5. Modify your Python script to GET the Google homepage.

  6. Try curl -i https://webdocs.cs.ualberta.ca/~hindle1/1.py

  7. Try it again curl -i -X POST -d "X=Y"

  8. Commit your Python script and push it to GitHub.

  9. Find the raw URL to your Python script on GitHub.
  10. Modify your Python script so that it downloads itself from GitHub and prints out its own source code from GitHub.
  11. Push the new version of your Python script to GitHub.

    • Question 8: What is the raw URL to your Python script on GitHub?