May i know what does this means:
def query_pokeapi(resource_url):
url = '{0}{1}'.format(BASE_URL, resource_url)
response = requests.get(url)
the '{0}{1}' and resource_url
On Wednesday, January 17, 2018 at 3:02:06 PM UTC+9, Matemática A3K wrote:
>
>
>
> On Wed, Jan 17, 2018 at 1:42 AM, <[email protected] <javascript:>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> 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 [email protected].
To post to this group, send email to [email protected].
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/40d656ab-675b-4f8d-b163-c155054d037f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.