1

To begin, yes there are other similarly titled questions, no this is not a duplicate.

I'm having a very odd problem when I'm using python and CGI on my webserver.

The following gives the indicated error

#! /python34/python
import cgi, Cookie, os
print("Content-Type: text/html\n")
print("Output")

However, if I don't import Cookie, it works

#! /python34/python
import cgi, os
print("Content-Type: text/html\n")
print("Output")

Any ideas on this?

4
  • Going to keep saying this: you should not be using CGI. There are much better solutions. Commented Aug 21, 2014 at 8:57
  • Meanwhile, have you installed a library called "Cookie"? Which one? Commented Aug 21, 2014 at 8:58
  • @DanielRoseman, whatever is the default. I didn't manually install anything, I was just following a tutorial and it worked. I'd like to get this working, but what other frameworks would you suggest? Commented Aug 21, 2014 at 9:08
  • There is no default library called "Cookie". That's why this doesn't work, because you can't import something that doesn't exist. As far as other alternatives are concerned, it depends on your requirements, but for a microframework look at Flask, or a full-featured one try Django. Commented Aug 21, 2014 at 9:10

1 Answer 1

1

The tutorial you're following is likely for Python 2. The Cookie library was renamed to http.cookies in Python 3. If you run 2to3 over your code it should highlight any changes you need to make.

https://docs.python.org/2/library/cookie.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.