I run bellow code in python 2.7 it work good :
from suds.client import client
client = Client(self.service_address)
rid = client.service.bpPayRequest(terminalId=self.terminalId,
userName=self.userName,
userPassword=self.userPassword,
orderId=order_id,
amount=price,
localDate=local_date,
localTime=local_time,
additionalData=additional_data,
callBackUrl=call_back_address,
payerId=0)
But when i run in python 3.6.2,it does not work.I guess Client is for python 2.How use suds.client library in python 3.6.2 and run top code in python 3.6.2?
Try to use
$ pip install suds-py3
It works for python 3.7.
Related
I have a program that displays the country belongs to the Ip address.Its working fine in version python 2.7.The problem is when i try the same program in version python 3.5 ,it throws an error as mentioned below:
Code:
from geoip import geolite2
m = geolite2.lookup('17.0.0.1')
Error:
TypeError: a bytes-like object is required, not 'str'
How can i resolve the error?
Thanks in advance
The answer above was correct to install the right package for Python3. To force installation for Python3 use:
python3 -m pip install python-geoip-python3
However, to benefit from the full functionality of geoip you may also consider downloading additionally geolite2 that also ships the IP database with it:
python3 -m pip install python-geoip-geolite2
To check if it works for you:
run python3 in interactive mode
run following:
>>> from geoip import geolite2
>>> geolite2.lookup('8.8.8.8')
You should get something like this
<IPInfo ip='8.8.8.8' country='US' continent='NA' subdivisions=frozenset({'CA'}) ...
you need to use the python 3 library:
pip install python-geoip-python3
I don't think the lib https://github.com/mitsuhiko/python-geoip will work in Python 3.x.
I looked at the source code in GitHub; it is 5 years without updates, and it still uses Python 2.x constructs (like xrange() in this line geoip.py#L255) that will not work in Python 3.x (maybe you get lucky and your code doesn't call the parts of the code with old constructs, but I wouldn't hold my breath).
It looks like you will have to clone the repo and adapt it to 3.x yourself or look for alternatives.
I'm developing a WPF IronPython application with VS 2015. I have to send a SOAP call and to read the answer so I'm trying to get suds to work. Since both pip and easy_install failed to install it, I downloaded the sources, unzipped them, and put them in the site-packages folder. It worked, now I can see them from VS.
When I try to use these modules however the program crashes, this is what I have done:
from suds import *
from suds.client import Client
class Utils(object):
def doStuff(addr, mail):
cl = Client(addr, verify=False)
cl.service.authenticate(email)
cl.service.otherFunctions(...)
I know that not every module works with IronPython, so my question is: have I made some error? Or is it suds that doesn't work with IronPython? If the second, do you know of alternatives?
Thank you.
My code is no longer working after moving from Python 2.7.9 to Python 3.4.3. I am trying to get my little program to run on my RPI and when I tried running with 2.7.9 via python server.py I get this error:
Code Issue:
def setVolume(volume):
volume = max(90, min(30, volume)) #Max Volume Spam Protection
sendPost(speakerAddress+"volume","<volume>"+str(volume)+"</volume>")
You are importing Request object and yet you are trying to
return request.urlopen(address).read()
As far as I know you can keep your old from urllib import request in the new code aswell. Here's what Python 3.4.3 docs say about it: https://docs.python.org/3/library/urllib.request.html
So you should be able to import request and parse from urllib in Python 3.4.3. If that doesn't work for you maybe consider reinstalling your Python 3.4.3 distribution.
When I do Python UDF with Pig, how do we know which version of Python it is using? Is it possible to use a specific version of Python?
Specifically my problem is in my UDF, I need to use a function in math module math.erf() which is newly introduced in Python version 2.7. I have Python 2.7 installed on my machine and standalone Python program runs fine but when I run it in Pig as Python UDF, I got this:
AttributeError: type object 'org.python.modules.math' has no attribute 'erf'
My guess is Jython is using some pre-2.7 version of Python?
Thanks for your help!
To get the version you are using you can do this:
myUDFS.py
#!/usr/bin/python
import sys
#outputSchema('bar: chararray')
def my_func(foo):
print sys.version
return foo
If you run the script locally then the version will be printed directly to stdout. To see the output of sys.version when you run it remotely you'll have to check the logs on the job tracker.
However, you are right about Jython being pre-2.7 (kind of). The current stable version of Jython right now is 2.5.3, so this is the version that Pig is using. There is a beta version of 2.7.
I have a website that loads/displays by grabbing the HTML from an SQLite3 database & displaying that (so if the user is on a Smart phone it will grab different HTML from the database than for someone on IE). I use python scripts as the server side behaviour to interact with the SQLite3 database & post the HTML.
My problem is: I am hosting the website with BlueHost & they only allow python 2.4 to run & the python SQLite3 module is a feature of Python 2.6 (or 2.7) & up. So my python scripts dont work when they run on BlueHost.
What do you think I can do to get my website to still use SQLite3 on the website? Are there any options for me? Maybe I can upload the Python module my fodler where my python scripts are?
The sqlite3 module in python 2.5+ is based on the pysqlite package, which does work for python 2.4. You can instead install that package and swap the import, then you can use it with less work.
One option to support both methods is to use a conditional import, like this:
try:
import sqlite3
except ImportError:
from pysqlite import dbapi2 as sqlite3