# Weatherstack.com api

**URL:** <https://forum.rasa.com/t/weatherstack-com-api/30814>\
**Category:** Rasa Open Source\
**Created:** [June 30, 2020, 2:08am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814 "2020-06-30T02:08:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![medion87](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/medion87/32/10126_2.png) [@medion87](https://forum.rasa.com/u/medion87)\
**Post date:** [June 30, 2020, 2:08am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/1 "2020-06-30T02:08:43Z")

</div>

Hi I’m pretty new to python. I try to make a chatbot with rasa for personal use. Would like to add weather api now. I use [weatherstack.com](http://weatherstack.com). If I use their example this works, but if I adjust it to my own liking I always end up with the same error.

> `condition = api_response['current']['weather_descriptions'] TypeError: list indices must be integers or slices, not str`

This is the code I am using.

> class Actionweatherapi(Action): def name(self): return “actions.weatherapi”

```auto
def run(self, dispatcher, tracker, domain):
    import requests
    location = tracker.get_slot('location')
    if location == 'None':
        location = 'fetch:ip'
    api_result = requests.get('http://api.weatherstack.com/current?access_key=0000000&query={}'.format(location))
    api_response = api_result.json()
    country = api_response['request']['query']
    condition = api_response['current']['weather_descriptions']
    temperature_c = api_response['current']['temperature']
    humidity = api_response['current']['humidity']
    wind_mph = api_response['current']['wind_speed']
    response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, country, temperature_c, humidity, wind_mph)
    dispatcher.utter_message(response)
    return [AllSlotsReset()]

```

I have also reviewed the printf-style String Formatting on the python website, but I cannot figure out how to get it working.

The json response is like this example [http://api.weatherstack.com/current?access\_key=1c80e8b9fe4fcef4f8d6fd7514a8e9e9&query=New%20York](http://api.weatherstack.com/current?access_key=1c80e8b9fe4fcef4f8d6fd7514a8e9e9&query=New%20York)

I did a great deal thanks to JustinaPetr’s Weatherbot Tutorial but they use ApixuClient but it has been taken over by weatherstack.

---

<div class="post-metadata">

**Author:** ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)\
**Post date:** [June 30, 2020, 4:46am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/2 "2020-06-30T04:46:29Z")

</div>

Hi @medion87,

Welcome to Rasa Community!

Have you passed your access key. In your `access_key variable`.

Are you getting any response from the requests you are sending.

` api_result = requests.get('http://api.weatherstack.com/current?access_key=0000000&query={}'.format(location))`

`api_response = api_result.json()`

can you print `print("api_response ",api_response)` after api\_response. share your results

---

<div class="post-metadata">

**Author:** ![medion87](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/medion87/32/10126_2.png) [@medion87](https://forum.rasa.com/u/medion87)\
**Post date:** [June 30, 2020, 7:22am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/3 "2020-06-30T07:22:29Z")

</div>

Hey thx for welcoming me, Yes I just changed the key for this post. If I try their example with only response locaction and temperature.

I get this as an example:

 ![Screenshot from 2020-06-29 23-22-14](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/4/485b2268d1c38e20b71fa9937bb4f24189ebedd1.png)

If I change action script to how I would like it, I get this as a response in the actions server

> Exception occurred while handling uri: ‘[http://localhost:5055/webhook](http://localhost:5055/webhook)’ Traceback (most recent call last): File “/home/bjorn/venv/lib/python3.6/site-packages/sanic/app.py”, line 976, in handle\_request response = await response File “/home/bjorn/venv/lib/python3.6/site-packages/rasa\_sdk/endpoint.py”, line 102, in webhook result = await executor.run(action\_call) File “/home/bjorn/venv/lib/python3.6/site-packages/rasa\_sdk/executor.py”, line 385, in run events = await action(dispatcher, tracker, domain) File “/home/bjorn/venv/lib/python3.6/site-packages/rasa\_sdk/interfaces.py”, line 254, in run raise NotImplementedError(“An action must implement its run method”) NotImplementedError: An action must implement its run method

I know there is something wrong in the script how I handle the json data output, but don’t know how to get it done.

---

<div class="post-metadata">

**Author:** ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)\
**Post date:** [June 30, 2020, 7:34am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/4 "2020-06-30T07:34:30Z")

</div>

Can you share your `actions.py. You can upload it here, I will take look into it.

---

<div class="post-metadata">

**Author:** ![medion87](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/medion87/32/10126_2.png) [@medion87](https://forum.rasa.com/u/medion87)\
**Post date:** [June 30, 2020, 8:15am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/5 "2020-06-30T08:15:52Z")

</div>

[actions.py](https://forum.rasa.com/uploads/short-url/lSrcKVWWO8UvEhkb571973RKfP5.py) (18.8 KB)

Thanks for looking at this for me

---

<div class="post-metadata">

**Author:** ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)\
**Post date:** [June 30, 2020, 8:33am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/6 "2020-06-30T08:33:00Z")

</div>

@medion87,

Everything is working fine, It just had indentation error, If you are using `vscode`, you can download `Python` from the market place and format the document easily. Your code is working like a charm. I indented properly and uploaded it here. 🙂

[actions.py](https://forum.rasa.com/uploads/short-url/5sxUcZ43kKI0yQkjnRiIITG7dqb.py) (18.9 KB)

 ![W](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/9/9e10b98c37d897c5459f9119956c4737b789c16e.png)

---

<div class="post-metadata">

**Author:** ![medion87](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/medion87/32/10126_2.png) [@medion87](https://forum.rasa.com/u/medion87)\
**Post date:** [June 30, 2020, 9:03am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/7 "2020-06-30T09:03:11Z")

</div>

Thank you Murali you really helped me with this. It works perfectly now, I had been working on this for 2 days and did not understand what was wrong. Something so small takes me so much time :-D. I am using Atom, but will consider installing vcode. You made me day.

---

<div class="post-metadata">

**Author:** ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)\
**Post date:** [June 30, 2020, 9:05am UTC](https://forum.rasa.com/t/weatherstack-com-api/30814/8 "2020-06-30T09:05:04Z")

</div>

No Problem 😁
