user41992 user41992 - 11 months ago 70
Python Question

get() takes exactly 1 argument (3 given)

#!/usr/bin/env python
import requests, json

userinput = raw_input('Enter a keyword: ')

getparams = {'order':'desc', 'sort':'votes', 'intitle':userinput, 'site':'stackoverflow', 'filter': '!5-HwXhXgkSnzI0yfp0WqsC_-6BehEi(fRTZ7eg'}

r = requests.get('', params=getparams)

result = json.loads(r.text)

if result['has_more'] == False:
print 'Error given.'
for looping in result['items']:
print ''
print ''
print 'Title:', looping['title']
#print 'Question:', looping['body']
print 'Link:', looping['link']
if looping['is_answered'] == True:
print 'Answer ID#:', looping['accepted_answer_id']
newparams = {'order':'desc', 'sort':'votes', 'site':'stackoverflow', 'filter': '!4(Yrwr)RRK6oy2JSD'}
newr = requests.get('', looping['accepted_answer_id'], params=newparams)
newresult = json.loads(newr.text)
print newresult['items'][0]['body']
except KeyError: print 'No answer ID found.'
print ''
print ''

I am trying to make a request such as " (User inputs 12345)" but I don't know how to do that. And if I include a string it returns error. Help, please?

I am getting this error:

Enter a keyword: php

Title: How can I prevent SQL-injection in PHP?
Answer ID#: 60496
Traceback (most recent call last):
File "./", line 25, in <module>
newr = requests.get('', looping['accepted_answer_id'], params=newparams)
TypeError: get() takes exactly 1 argument (3 given)

Answer Source

update the request line as

newr = requests.get(''+str(looping['accepted_answer_id']), params=newparams) 

you need to concatenate the looping['accepeted answer']