0

In my code Im trying to get the user to log in and retrive some information, but I get a syntax error with my variables user and password. bold print is commented out in code

import urllib.request
import time
import pycurl
#Log in
user = input('Please enter your EoBot.com email: ')
password = input('Please enter your password: ')
#gets user ID number
c = pycurl.Curl()
#Error below this line with "user" and "password"
c.setopt(c.URL, "https://www.eobot.com/api.aspx?email="user"&password="password")
c.perform()
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
user3897196
  • 17
  • 1
  • 2

3 Answers3

0

You must escape double quotation character in string by doubling it(or by using single quotes also):

c.setopt(c.URL, "https://www.eobot.com/api.aspx?email=""user""&password=""password""")

but really it must be like this:

from urllib import parse

# ...
# your code
# ...

url = 'https://www.eobot.com/api.aspx?email={}&password={}'.format(parse.quote(user), parse.quote(password))
c.setopt(c.URL, url)

This service don't want from you to send quotes in uri. But special characters(like '@') must be url-encoded by 'quote' or 'urlencode' methods from 'urllib.parse' class

rufanov
  • 3,266
  • 1
  • 23
  • 41
  • I love this method for my project thank you very much. now if i want to use numbers and not words would i still use the .quote still or something else – user3897196 Aug 06 '14 at 02:27
  • @user3897196, well.. with numbers url-encoding it's not really needed(there is noting to encode), so you can skip it. – rufanov Aug 06 '14 at 04:14
0

You need to escape your quotation marks inside the string, or use single quotes on the outside.

c.setopt(c.URL, 'https://www.eobot.com/api.aspx?email="user"&password="password"')
merlin2011
  • 71,677
  • 44
  • 195
  • 329
0

Nope. Start over.

import urllib.parse

 ...

qs = urllib.parse.urlencode((('email', user), ('password', password)))
url = urllib.parse.urlunparse(('https', 'www.eobot.com', 'api.aspx', '', qs, ''))
c.setopt(c.URL, url)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358