0

I'm trying to convert a code from python 2 to python 3, that makes a request from simsimi api.

Python 2 code :

# -*- coding: utf- -*-

import urllib
import urllib2

url = "http://sandbox.api.simsimi.com/request.p?"

text_input = raw_input("Input your text: ")
lc_input = raw_input("Input your lc: ")
text = text_input.encode("utf-8")
lc = lc_input.encode("utf-8")
values = {'key' : 'api key',
      'lc' : lc,
      'ft' : '0.0',
  'text' : text}

data = urllib.urlencode(values)
request_url = urllib2.Request(url, data)
response_post = urllib2.urlopen(request_url)
response = response_post.read().decode("utf-8")
print response

Python 3 code(result):

# -*- coding: utf- -*-

import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse

url = "http://sandbox.api.simsimi.com/request.p?"

text_input = input("Input your text: ")
lc_input = input("Input your lc: ")
text = text_input.encode("utf-8")
lc = lc_input.encode("utf-8")
values = {'key' : 'api key',
      'lc' : lc,
      'ft' : '0.0',
  'text' : text}

data = urllib.parse.urlencode(values)
request_url = urllib.request.Request(url, data)
response_post = urllib.request.urlopen(request_url).encode("utf-8")
response = response_post.read().decode("utf-8")
print(response)

When I run the python 3 code, I get this error:

console error

martineau
  • 119,623
  • 25
  • 170
  • 301
SoxxZ _
  • 21
  • 1

0 Answers0