如何创建User Agent以解决edgarwebR访问SEC EDGAR时的请求拦截问题
Hey there! That error is super common when starting out with EDGAR tools—SEC requires all automated requests to include a clear User Agent so they can reach you if there's any issue with your traffic. Let's fix this quickly.
First, you need a valid User Agent string. The SEC recommends using your full name plus a working email address (this is non-negotiable for compliance). For example:"Rachael Loh <rachael.loh@example.com>"
You have two easy ways to set this up:
1. Temporary Setup (Current R Session Only)
Run this line before your edgarWebR code to set the environment variable for your current session:
Sys.setenv(EDGARWEBR_USER_AGENT = "Your Full Name <your.email@example.com>")
Then go ahead and run your original code again:
x <- paste0("https://www.sec.gov/Archives/edgar/data/", "933691/000119312517247698/0001193125-17-247698-index.htm") try(filing_information(x))
2. Permanent Setup (Applies to All Future R Sessions)
If you don't want to set this every time you open R, add the environment variable to your .Rprofile file:
- Run
usethis::edit_r_profile()in R to open your profile file (install theusethispackage first if you don't have it:install.packages("usethis")) - Add this line to the file:
Sys.setenv(EDGARWEBR_USER_AGENT = "Your Full Name <your.email@example.com>") - Save the file and restart R. Now the User Agent will be set automatically every time you launch R.
Just make sure you use a real, reachable email—this is part of SEC's fair access guidelines, and it helps them avoid flagging your requests as suspicious.
内容的提问来源于stack exchange,提问作者Rachael Loh

