I am trying to pull the quarter end dates for a company from the SEC government website. For some reason I keep getting a connection error. The code is working for my friend who is in the US, but not for me in Canada. I tried using a VPN, but was still getting the same error. Here is the code and the error that I was getting.
When I put the url into google it brings me to the page with all the information so I am not sure why I cant pull it into R.
library(derivmkts)
library(quantmod)
library(jsonlite)
library(tidyverse)
url = "https://data.sec.gov/submissions/CIK0000320193.json"
df <- fromJSON(url, flatten = T)
Error in open.connection(con, "rb") :
cannot open the connection to 'https://data.sec.gov/submissions/CIK0000320193.json'
In addition: Warning message:
In open.connection(con, "rb") :
cannot open URL 'https://data.sec.gov/submissions/CIK0000320193.json': HTTP status was '403 Forbidden'
I am not expecting a 403 error when connecting to this url
They ask you to declare user agent in request headers - https://www.sec.gov/os/accessing-edgar-data
Apparently the one provided as an example is also accepted, though you really should provide your contact details there.
With
httr2, it still usesjsonlitefor parsing JSON responses:Created on 2023-07-27 with reprex v2.0.2
I'm from EU, I can open that JSON URL in the browser without any issues, but default
jsonlite&httr2agents are blocked. Using my browser's agent withhttr2works only when I also setaccept-language. They check for some weird pattern in user agent when request is not coming from browser,i.e.
"foo_bar"- NOK /"foo.bar"- OK