Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yahoo unhappy about crumbs #393

Closed
eddelbuettel opened this issue Jul 25, 2023 · 6 comments · Fixed by #395
Closed

Yahoo unhappy about crumbs #393

eddelbuettel opened this issue Jul 25, 2023 · 6 comments · Fixed by #395

Comments

@eddelbuettel
Copy link

Description

getQuote() is no longer working.

Expected behavior

getQuote("SPY") etc worked but no longer does

Minimal, reproducible example

> quantmod::getQuote("SPY")
Error in .yahooSession(TRUE) : unable to get yahoo crumb
> quantmod:::.yahooSession()
Error in .yahooSession(TRUE) : unable to get yahoo crumb
> quantmod:::.yahooSession(TRUE)
Error in quantmod:::.yahooSession(TRUE) : unable to get yahoo crumb
> 

Session Info

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 23.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Chicago
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quantmod_0.4.24 TTR_0.24.3      xts_0.13.1      zoo_1.8-12     

loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1    parallel_4.3.1 colorout_1.2-2 curl_5.0.1     grid_4.3.1     jsonlite_1.8.7 lattice_0.21-8 fortunes_1.5-4
> 
@ethanbsmith
Copy link
Contributor

can you try this branch: remotes::install_github("ethanbsmith/quantmod@fix_404_handle_getquote_gdpr_errors")

@eddelbuettel
Copy link
Author

Works like a charm after a quick (command-line, via littler)

  installGithub.r ethanbsmith/quantmod@fix_404_handle_getquote_gdpr_errors

(which of course wraps the remotes call). All good so suggest to merge.

@eddelbuettel
Copy link
Author

eddelbuettel commented Jul 25, 2023

And just for completeness as I use this in a loop storing in Redis (details on my blog / in package dang / happy to expand): Behavior change apparently commenced at 23:00h Central yesterday or 00:00h Eastern.

@rjvelasquezm
Copy link

I can confirm this fix is working for me as well.

@joshuaulrich
Copy link
Owner

This seems to be caused by a missing "User-Agent" in the current request header. Ethan's patch added a user-agent in addition to improving the error message.

And it's not good enough for the user-agent to be set to something. It needs to be a value the server considers valid, like it is in Ethan's patch. I tried setting it to "R (4.3.1, x86_64-pc-linux-gnu, x86_64, linux-gnu)" but the request still failed.

@ethanbsmith
Copy link
Contributor

this is the second change yahoo has made in the last few months that treats scripting differently than actual browsers. i fear this api is not long for this world. just my .02

@joshuaulrich joshuaulrich added this to the Release 0.4.25 milestone Jul 27, 2023
joshuaulrich added a commit that referenced this issue Jul 27, 2023
Yahoo Finance requires GDPR consent in some countries. We can't
automatically consent for the user, so the data request fails with an
ambiguous 404 error.

Yahoo also started to require a User-Agent in the header.

Fixes #392. Fixes #393.

Co-authored-by: Ethan Smith <[email protected]>
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 4, 2025
### Changes in 0.4.25 (2023-08-21)

1. Fix `getQuote.yahoo()` for API changes. Thanks to Ethan B. Smith for the
    report and patch! Also add error message for users in GDPR countries, since
    we cannot automatically consent to GDPR and the request fails without
    consent.
    [#392](joshuaulrich/quantmod#392)
    [#393](joshuaulrich/quantmod#393)
    [#395](joshuaulrich/quantmod#395)

1. Fix `getQuote.yahoo()` when the user only requested metrics that do not have
    have a value for 'regularMarketTime'. Set the value to NA in these cases
    so the output remains the same regardless of whether the endpoint returns
    a 'regularMarketTime' or not. Thanks to @mehdiMBH for the report!
    [#255](joshuaulrich/quantmod#255)

1. Add fields to `getQuote.yahoo()` that are returned when no fields are
    explicitly requested. Thanks to @Courvoisier13 for the report!
    [#335](joshuaulrich/quantmod#335)

1. Add intraday endpoint to `getSymbols.yahoo()`. Thanks to @kapsner for the
    report and patch! Also allow suppressing the warning if more than 7 days
    of data are requested (@eddelbuettel).
    [#351](joshuaulrich/quantmod#351)
    [#381](joshuaulrich/quantmod#381)
    [#399](joshuaulrich/quantmod#399)

1. Add warning if `getSymbols()` is called with tickers that are reserved words
    because accessing them requires back-quotes (e.g. ``NA``).
    [#401](joshuaulrich/quantmod#401)

1. Fix `allReturns()` when 'subset' is specified. Thanks to @Panagis1980 for
    the report!
    [#402](joshuaulrich/quantmod#402)

### Changes in 0.4.24 (2023-07-17)

1. Fix `getSymbols.oanda()` URL. Thanks to @macray76 for the report.
    [#387](joshuaulrich/quantmod#387)

### Changes in 0.4.23 (2023-06-14)

1. Fix `getQuote.yahoo()` error. Thanks to Ethan B. Smith for the report and
    patch!
    [#382](joshuaulrich/quantmod#382)
    [#383](joshuaulrich/quantmod#383)

1. Add `name` argument to `add_TA()`. Thanks to @SamoPP for the suggestion!
    [#377](joshuaulrich/quantmod#377)
    [#205](joshuaulrich/quantmod#205)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants