简体   繁体   中英

What are the date constraints for SimilarWeb visits API? Python request to traffic API gives 'Dates not in range' error

I'm trying to get data from the SimilarWeb API , using python requests, like this:

import requests
MY_API_KEY = 'XXXXXXXXXXXXXXXXXX'

API_URL = "https://api.similarweb.com/v1/website/{site}/" \
          "total-traffic-and-engagement/visits?api_key={api_key}" \
          "&start_date={start_date}" \
          "&end_date={end_date}" \
          "&main_domain_only=false" \
          "&granularity={granularity}".format(
    site='cnn.com',
    api_key=MY_API_KEY,
    start_date="2017-09",
    end_date="2017-10",
    granularity="monthly"
)

response = requests.get(API_URL)
print response.json()

As far as possible, this follows the similarweb example on their own site here . Only the dates are different.

However, I get a json error stating that my 'Dates not in range' within the json:

{
    u'meta': {
        u'status': u'Error', 
        u'error_code': 101, 
        u'error_message': u'Dates not in range', <--- error msg
        u'request': {
            u'domain': u'cnn.com', 
            u'end_date': u'2017-10-31', 
            u'format': None, 
            u'country': u'world', 
            u'main_domain_only': False, 
            u'limit': None, 
            u'granularity': u'Monthly', 
            u'start_date': u'2017-09-01'
        }
    }
}

I have tried many different dates (including the ones in the example - start_date=2016-01&end_date=2016-03), and I have tried different date formats, but I always get this error. I have tried dates further in the past, and I have tried dates further apart.

If I leave the dates out, I am returned valid data, so I believe the rest of the request must be well formed? I will continue to try different options, but would be really grateful if anyone has had experience with this, as it is driving me a little crazy now!

I am using python 2.7 due to project constraints, with requests version 2.18.4, which I believe to be the most recent available to pip.

You're requesting 2017-09 to 2017-10, Today's Nov 1st so the 2017-10 snapshot is not up yet. contact SimilarWeb support for updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM