VS2017 Python 3.10 getting unexpected token errors and invalid Syntax errors - settings issue? - visual-studio-2017

My code runs on VSCode but running on VS2017 I get many unexpected token and invalid syntax errors.
code
def print_now():
current_time = datetime.datetime.now()
now = current_time.strftime("%D %T")
print(now)
def numTimesDecision():
print("Inside numTimesDecision",end=" ") #ERROR: unexpected token '=',
#unexpected token '<newline>'
print_now() #ERROR: unexpected token 'print_now'
checkButtonSun = f"{playingSun.get()}" #ERROR: invalid syntax "{playingSun.get()}"
checkButtonMon = f"{playingMon.get()}"
checkButtonTue = f"{playingTue.get()}"
checkButtonWed = f"{playingWed.get()}"
checkButtonThu = f"{playingThu.get()}"
checkButtonFri = f"{playingFri.get()}"
checkButtonSat = f"{playingSat.get()}"
How do I get rid of these errors? Is there something in settings that's not set correctly?

Related

syntax error: invalid syntax -Django View

Below is my hello apps view.py
***def hello(request):
num_visits = request.session.get('num_visits',0)+1
request.session['num_visits'] = num_visits
if num_visits > 4 : del(request.session['num_visits']
return HttpResponse(';view count ='+str(num_visits))***
after compile, check below error appear on shell:
Syntax Error - Invalid Syntax
Can any expert provide some guidance ?
del doesn't take arguments in parenthesis, it's an operator.
Change this line:
del(request.session['num_visits']
to:
del request.session['num_visits']
And it should work.
thank you for the respond, i managed to address the problem, there was a missing ")" at the del line.

error trying to download a report with a variable that changes via python 2.7

Error: cannot concatenate 'str' and 'int' objects
Trying to download a report automatically from our qualys vulnerability scanner, however i'm getting an error due to the variable being an integer and not a string, i understand i need to do str(variable) name, but it doesn't work
newreportID is throwing the error at line 8 with the error above
def downloadReport(s, newreportID):
# ---Download reports---
payload = {
'action':'fetch',
'id': newreportID,
}
r = s.post('https://qualysapi.qg2.apps.qualys.com:443/api/2.0/fo/report/', data=payload)
with open("Z:/Shared/Scan_Report_"+ newreportID +".csv", "wb") as report:
report.write(r.content)
def main(newreportID):
s = requests.Session()
s.headers.update({'X-Requested-With':'Facklers PyQual python primer'})
login(s)
listReports(s, newreportID)
downloadReport(s, newreportID)
logout(s)
s.close()
if __name__ == "__main__": main(newreportID)

wolframalpha api syntax error

i am working on 'wolframalpha' api and i am keep getting this error, i tried to search but not getting any working post on this error if you know please help me to fix this error
File "jal.py", line 9
app_id=’PR5756-H3EP749GGH'
^
SyntaxError: invalid syntax
please help; i have to show project tomorrow :(
my code is
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wolframalpha
import sys
app_id=’PR5756-H3EP749GGH'
client = wolframalpha.Client(app_id)
query = ‘ ‘.join(sys.argv[1:])
res = client.query(query)
if len(res.pods) > 0:
texts = “”
pod = res.pods[1]
if pod.text:
texts = pod.text
else:
texts = “I have no answer for that”
# to skip ascii character in case of error
texts = texts.encode(‘ascii’, ‘ignore’)
print texts
else:
print “Sorry, I am not sure.”
You used a backtick (´) instead of a single-quote (').
app_id='PR5756-H3EP749GGH'
Python directly shows you the error.
Also, use an editor with text highlighting.

error bash: syntax error near unexpected token `(' my code is correct

I am trying to implement a hash function and here is my code:
import BitVector
import glob
path = '/home/vguda/Desktop/.txt'
files=glob.glob(path)
hash = BitVector.BitVector(size = 32)
hash.reset(0)
i = 0
for file in files:
bv = BitVector.BitVector( filename = file )
while 1 :
bv1 = bv.read_bits_from_file(8)
if str(bv1) == "":
break
hash[0:8] = bv1 ^ hash[0:8]
hash >> 8
i = i+1
hash_str = ""
hash_str = str( hash )
text_file = open("/home/vguda/Desktop/result.txt ","w")
text_file.write("Hash Code is %s" %hash_str)
text_file.close()
print hash
print (i)
The displayed error is:
"bash: syntax error near unexpected token `('
First, perhaps this happened in copy and paste, but your indenting in your loop is all messed up, I'm not sure which blocks go where.
When you run things in the shell, you need to either tell python to run it:
python myscript.py
Or, put the following line as the first thing in your program to tell bash to run it as a python program:
#!/usr/bin/python
Currently, bash is trying to run your python program as a bash script, and obviously running into syntax errors.

Unit testing captcha in yii

How to unit test a form with captcha?
I get this error:
Fatal error: Call to a member function createAction() on a non-object in framework/validators/CCaptchaValidator.php on line 65
How can I fix this error?
I have tried the code below:
$c = Yii::app()->createController('module/action');
Yii::app()->controller = $c[0];
$captcha = new CCaptchaAction(Yii::app()->controller, 'captcha');
$model->captcha = $captcha->getVerifyCode();
but I get the error below:
Fatal error: Call to a member function getUniqueId() on a non-object in C:\xampp\htdocs\yii\framework\web\widgets\captcha\CCaptchaAction.php on line 221
any ideas?
i fix this error by ignoring captcha rule and give it a custom value and it works!
i remove this part of rules in my form:
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements())