0

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()
1
  • 2
    Thus far you don't even attempt to put the values into the placeholders. Commented Mar 28, 2016 at 11:53

1 Answer 1

5

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.

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

2 Comments

you might have to str() any numeric values in the tuple as the pattern expects 3 strings. I don't recall what year month and day are in that structure of the top of my head.
Actually, according to docs(that table, 's') each passed object is converted automatically with str(). However if not sure, better use than sorry. :)

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.