invalid character in identifier error in Python code
The seems to be the double quotes you used, you used “
which is different then "
.
This means that python didn't know it is a string, and this is why you got a syntax error.
This can be a problem with your text editor, i would recommand using sublime text or npp.
And another thing, what you are trying to do probably won't work, since if there's an error retriving the matches, you can't be sure the dict will have the key "data"
.
I would recommand using try-except to know if the response contains any data, or using
d = r.json()
if "data" in d:
print "Got data"
else:
print "Error getting data"
Related videos on Youtube
Vrajesh Doshi
I am working as Web Developer at Margosa Tree LLP. My key interests and skillset include PHP, javascript, jQuery, AJAX, HTML5, CSS, working with Google maps APIs and Web Push Notifications. I am currently working on PHP frameworks: Codeigniter and Laravel. My domain interests are Software Engineering, Education Technology, Image Processing, Algorithm Analysis. I have published research papers at IEEE conferences and in Peer reviewed international journal, the links to which can be found below. Competitor Driven Development: Hybrid of Extreme Programming and Feature Driven Reuse Development. Realizing Students' Understanding through Rule Based Reasoning. State of the Art Technique for Recognizing Understanding of Learners'
Updated on June 04, 2022Comments
-
Vrajesh Doshi almost 2 years
I am getting "invalid character in identifier" error, for the below code. The 'http' in line 3 gets highlighted when the error is shown. I am new to Python, please help.
import requests import html r = requests.get(“http://cricapi.com/api/cricket”) if r.status_code == 200: currentMatches = r.json()[“data”] for match in currentMatches: print(html.unescape(match[“title”])) else: print(“Error in retrieving the current cricket matches”)
-
Robin over 6 yearstry using normal quote characters? " instead of “
-
Vrajesh Doshi over 6 yearsThank You, the error got removed but not getting any output
-
Manoj Jadhav over 6 years@VrajeshDoshi check
r.text
. you will get to know what API does expect. -
Vrajesh Doshi over 6 yearsGetting Error: ImportError: No module named html
-
Vrajesh Doshi over 6 yearsGot it, it was expecting apikey
-
hyper-neutrino over 6 yearsTry indenting your code? This could just be a copy-paste error because there is no way this code won't error.
-
Vrajesh Doshi over 6 yearsThanks HyperNeutrino, for your valuable input, but it already got resolved some times back.
-