Reputation: 802
i'm using the following to call a url , which I need to pass year/month/day as variable while calling it so the final url structure be like
http://mywebiste.com/downloading/main/2016/03/28/'
here is my code ,
import pycurl
import os, sys, re, shutil
import datetime
import time
import requests
import datetime
import logging
import httplib
#logging.basicConfig(level=logging.DEBUG)
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day
url = 'http://mywebiste.com/downloading/main/%s/%s/%s/'
r = requests.get(url,timeout=10)
r.text
r.status_code
r.connection.close()
Upvotes: 0
Views: 4705
Reputation: 12199
I think you want this:
url = 'http://mywebiste.com/downloading/main/%s/%s/%s/' % (year, month, day)
Little more explaining: for each string you want use with variables with %
way you need to use string as my_string = 'my value is: %s' % value
, where value is your variable.
Upvotes: 5