On Wed, Jan 17, 2018 at 1:42 AM, <cherngyo...@gmail.com> wrote:

> As this is the first time I'm trying this out, I do not know what is wrong
> with the problem. So it would be great if someone can help me solve this
> problem
>
>
> The code I'm using is at the bottom page of this website:
> https://www.twilio.com/blog/2014/11/build-your-
> own-pokedex-with-django-mms-and-pokeapi.html
>
> Where it give example on how you can make HTTP request function and
> retrieve database on your query.
>
>
> The code on the website is this.
>
> *query.py*
>
> import requestsimport json
>
> BASE_URL = 'http://pokeapi.co'
>
> def query_pokeapi(resource_url):
>     url = '{0}{1}'.format(BASE_URL, resource_url)
>     response = requests.get(url)
>
>     if response.status_code == 200:
>         return json.loads(response.text)
>     return None
>
> If there is not a 200 response it returns None

>
>
>
> charizard = query_pokeapi('/api/v1/pokemon/charizard/')
>
>
It's because charizard is None

>
> sprite_uri = charizard['sprites'][0]['resource_uri']
>
> that can't do None['sprites']...

>
> description_uri = charizard['descriptions'][0]['resource_uri']
>
> sprite = query_pokeapi(sprite_uri)
> description = query_pokeapi(description_uri)
> print
> charizard['name']print
> description['description']print
> BASE_URL + sprite['image']
>
>
> In my edit, I only change these print line at the bottom of this
>
> *query.py*
>
> print(charizard['name'])print(description['description'])print(BASE_URL + 
> sprite['image'])
>
>
> But i got this error instead
>
> Traceback (most recent call last): File "query2.py", line 46, in
> sprite_uri = charizard['sprites'][0]['resource_uri'] TypeError:
> 'NoneType' object is not subscriptable
>
> And that's why the error


> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/af20ad33-1843-4fff-93fb-8681f7d5b88e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/af20ad33-1843-4fff-93fb-8681f7d5b88e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhL16ko3%3Dcc%3D5f91t6_PKLcKPLNbK%3DEq-ap61G8GgYCRmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to