DSWS in RStudio - 403 error suddenly appearing

Sunil_T
Sunil_T Newcomer
edited July 29 in Datastream

Hi I've used Datastream on excel quite a lot - trying out the API through Rstudio first time. The below code worked perfectly till about a day ago, but has now started generating errors as shown. Pardon the formatting that is messed up on copying code and output below. As you can see the error is appearing on the call to the snapshotRequest.

I haven't changed anything in the login credentials in the .Renviron file

A seperate question - should the username and password in the .Renviron file (DatastreamUsername and DatastearmPassword) be within quotes? (it worked with quotes earlier - now trying both with and without quotes - no luck eitherways)

> library(httr)
> library(devtools)
> library(DatastreamDSWS2R)
> httr::set_config(
                              httr::use_proxy(
                              url = Sys.getenv("proxy_url"),
                              username = Sys.getenv("proxy_user"),
                              password = Sys.getenv("proxy_pass")
                                                       )
                               )
> mydsws <- dsws$new()
> myData <- mydsws$snapshotRequest(instrument = c("U:F","U:BA","U:CAT","U:CVX","U:KO","U:XOM","@INTC" ,"U:JNJ","U:IBM"),
                                  datatype = c("NAME", "EXNAME", "GEOGN", "TR1N","TR2N","TR3N", "TR4N","TR5N"),
                                  requestDate = "0D")

Request failed [403]. Retrying in 1 seconds...
Request failed [403]. Retrying in 2.2 seconds...
Error requesting data.  HTTP message was: Client error : Forbidden : Client error: (403) Forbidden

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Sunil_T

    Thank you for reaching out to us.

    I tested it and found that the Datastream username and password in the .Revniron file doesn't require quotes.

    DatastreamUsername=YOURUSERNAME
    DatastreamPassword=YOURPASSWORD

    You can test the credentials on the Datastream Test Rest Service Website.

    You can also run the code below to verify what the problem is.

    library(httr)
    DatastreamUsername <- "Username"
    DatastreamPassword <- "Password"
    token_url <- paste("http://product.datastream.com/DSWSClient/V1/DSService.svc/rest/Token?username=",
    DatastreamUsername,
    "&password=",
    DatastreamPassword,
    sep="")
    test <- httr::GET(token_url, httr::timeout(300))
    print(test)
    print(status_code(test))
    print(headers(test))
    print(content(test))

    After running, please remove your credential from the output and share it.