Token POST is not callable??

I am using Python 3.6, with Pycharm Community

I am trying to get a Token but keep getting object is not callable error?? I would appreciate any pointers to resolve this..

The error points at the line below,  the error msg = TypeError: 'str' object is not callable

req = urllib.request("POST"(tokenURL, urlencode(params)))
#### For Python 3
import os, sys
import ssl
import json

import urllib
import urllib.request
from urllib.request import urlopen
from urllib.parse import urlencode
from urllib.parse import urlparse
import http.client
import requests

params = {'f': 'pjson', 'username': username, 'password': password, 'referer': referer}

#For Python 3
req = urllib.request("POST"(tokenURL, urlencode(params)))
response = urllib.parse.urlopen(req)


try:
response = urllib.urlopen(req)
except:
gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
response = urllib.urlopen(req, context=gcontext)
data = json.load(response)
token = data['token']
print(token)


0
2 comments
Avatar
Permanently deleted user

I changed urllib.parse.urlopen to urlopen. Still get the same error??

0
Avatar
Permanently deleted user

I also tried the response option, get an OSError: Int or String expected??

 

conn = http.client.HTTPConnection(generateToken)
##conn.request("POST", "", params, headers)
response = conn.request("POST"("username=username&password=password&client=referer&referer=hostname&expiration=90&f=json"))
print(response)
0

Please sign in to leave a comment.