GitHub Actions downloads (probably) cached files

I have edited this post after tinkering a little bit.

This is a test file i created:

name: tests
on:
  workflow_dispatch:
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - name: Set up python 3.x
        uses: actions/setup-python@v2
        with:
          python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
          architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
      - run: pip install requests
      - run: python -c "import requests as A;import json;print(json.loads(A.get('https://www.pokemon.com/api/pokemontv/v2/channels/us/').content)[0])"

The last command prints always {'channel_description': 'Ash and Pikachu’s exciting adventu
When the URL is openend inside a browser or if the code is executed through python on my local pc, it always prints a newer version of the json, not containing what is printed through the GH Action.
So this is not a case of the json having items in a random order.

When working with APIs, id like to get a non-cached and up to date file. Why do i get an old one and how can i force a fresh one? Appending a timestamp as get parameter to make the url unique doesnt work.

Exactly how do you download the files? You mention the Python requests module and headers in the post, but how do you create the URLs?

with open('mappings.json') as json_file:
    mappings = json.load(json_file)
    for lang in mappings:
        currTime = str(int(time.time()))
        try:
            r = requests.get(mappings[lang]['apiUrl'] + "?time=" + currTime)
            rContent = r.content
        except:
            print("Error getting " + mappings[lang]['apiUrl'])
            continue
        try:
            a_json = json.loads(rContent)
            with open('./apiData/' + lang + '.json', 'wb') as f:
                f.write(rContent)

                if lang == "us":
                    print(a_json[0])
        except:
            print(mappings[lang]['apiUrl'])
            print("Could not be converted to JSON")

but how i “create” the url shouldnt be of importance right?

with this code ive even tried to add a timestamp at the end of the url to make it unique but that didnt work either. still getting the old file. and i am sure its downloaded because of the print(a_json[0]) line.

name: tests
on:
  workflow_dispatch:
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - name: Set up python 3.x
        uses: actions/setup-python@v2
        with:
          python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
          architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
      - run: pip install requests
      - run: python -c "import requests as A;import json;print(json.loads(A.get('https://www.pokemon.com/api/pokemontv/v2/channels/us/').content)[0])"

in my workflow, this prints {'channel_description': 'Ash and Pikachu’s exciting adventu
opening the url in the browser and searching for that string reveals that it doesnt exist

i have edited the title and first post to better reflect my issue

I meant the exact URL might matter, but with the one in the last example I don’t see a potential problem. There could be differences on the server side though. For example, there is a country_codes element in the response, so maybe there are different answers based on guessed location or something?

edit: nevermind. you are right

ive tested with a vpn again and i am getting different data based on the country i am in.
this makes no sense though. why would anyone have an api with /us, /de, etc endpoints and still deliver content based on the region?

1 Like