Question on write-docker-actions course

I’m doing this training GitHub Actions: Write Docker container actions | GitHub Learning Lab

And the hello world actions is not working. It fails in this step “RUN go get -d -v ./…”

Here is my repo:

write-docker-actions

Can anyone help me?

Thank you!

There’s something at the top of your main.go file that shouldn’t be there, probably a copy&paste mistake:

Thank you!! I corrected that and now it fails on the other action, it says:

File “/src/main.py”, line 8, in

67 r_obj_list = r.json()[“all”]

68TypeError: list indices must be integers or slices, not str

The error message precisely describes the problem: The JSON object you get there contains a list. You can’t use a string as the index for a list.

What are you trying to do?

I was just following the tutorial, this was the description:

Activity: Create the Python source code for the cat-fats action

  1. Create and add the following contents to the .github/actions/cat-facts/src/main.py file:
    You can use this link to easily create this file.

import requests
import random
import sys

Make an HTTP GET request to the cat-fact API

cat_url = “https://cat-fact.herokuapp.com/facts
r = requests.get(cat_url)
r_obj_list = r.json()[“all”]

Create an empty list to store individual facts in

This will make it easy to select a random one later

fact_list =

Add the “text” of every object into the fact_list

list for fact in r_obj_list:
fact_list.append(fact[“text”])

Select a random fact from the fact_list and return it

into a variable named random_fact so we can use it

def select_random_fact(fact_arr):
return fact_arr[random.randint(0, len(fact_list)+1)]
random_fact = select_random_fact(fact_list)

Print the individual randomly returned cat-fact

print(random_fact)

Set the fact-output of the action as the value of random_fact

print(f"::set-output name=fact::{random_fact}")

That looks like the suggested code doesn’t fit the data returned by the cat-fact API. If I call that URL I get this:

[{"status":{"verified":true,"sentCount":1,"feedback":""},"type":"cat","deleted":false,"_id":"5887e1d85c873e0011036889","user":"5a9ac18c7478810ea6c06381","text":"Cats make about 100 different sounds. Dogs make only about 10.","__v":0,"source":"user","updatedAt":"2020-09-03T16:39:39.578Z","createdAt":"2018-01-15T21:20:00.003Z","used":true},{"status":{"verified":true,"sentCount":1},"type":"cat","deleted":false,"_id":"588e746706ac2b00110e59ff","user":"588e6e8806ac2b00110e59c3","text":"Domestic cats spend about 70 percent of the day sleeping and 15 percent of the day grooming.","__v":0,"source":"user","updatedAt":"2020-08-26T20:20:02.359Z","createdAt":"2018-01-14T21:20:02.750Z","used":true},{"status":{"verified":true,"sentCount":1},"type":"cat","deleted":false,"_id":"58923f2fc3878c0011784c79","user":"5887e9f65c873e001103688d","text":"I don't know anything about cats.","__v":0,"source":"user","updatedAt":"2020-08-23T20:20:01.611Z","createdAt":"2018-02-25T21:20:03.060Z","used":false},{"status":{"verified":true,"sentCount":1},"type":"cat","deleted":false,"_id":"5894af975cdc7400113ef7f9","user":"5a9ac18c7478810ea6c06381","text":"The technical term for a cat’s hairball is a bezoar.","__v":0,"source":"user","updatedAt":"2020-11-25T21:20:03.895Z","createdAt":"2018-02-27T21:20:02.854Z","used":true},{"status":{"verified":true,"sentCount":1},"type":"cat","deleted":false,"_id":"58e007cc0aac31001185ecf5","user":"58e007480aac31001185ecef","text":"Cats are the most popular pet in the United States: There are 88 million pet cats and 74 million dogs.","__v":0,"source":"user","updatedAt":"2020-08-23T20:20:01.611Z","createdAt":"2018-03-01T21:20:02.713Z","used":false}]

You can add something like print(r.json()) right after the requests.get() call to see the data in your log.

At a glance it looks like the JSON object is already what r_obj_list should be, so you can probably just remove the ["all"] and directly assign r.json() to r_obj_list.

1 Like

Thaank you @airtower-luna!

It worked and I could finish the exercise!

1 Like