-1

Here is my code and output:

>>> import os
>>> url = os.environ['REQUEST_URI']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'REQUEST_URI'

The browser is Microsoft Edge on Windows 10 Home. The Python interpreter was bundled with Visual Studio.

I have seen How to get current URL in python web page?

Community
  • 1
  • 1
  • 1
    I'm confused, your code isn't even similar to the answers in the other stack overflow question. Edit: I see what you are referring to now. Why don't you try some of the other solutions on that question? That Stackoverflow question specifically says that the solution in the linked URL is not the answer. – CrizR Feb 16 '18 at 18:45
  • I apologize. I'm kind of new to StackOverflow and programming. I've edited my original post to clarify. – MickeyLater Feb 16 '18 at 18:58

1 Answers1

1

os.environ is a dictionary containing your environment variables.
I'm assuming you haven't set an environment variable for your url.
The easy way is to open command prompt and type setx REQUEST_URI "http://example.com"
Once you've set the environment variable, reload the script, and it should work.

Jeremiah
  • 623
  • 6
  • 13