jira-python invalid syntax - python

First time using jira-python, and I get this error when I run just a simple initialization.
from jira.client import JIRA
jira = JIRA()
Error:
File "C:\Python32\lib\site-packages\jira\resources.py", line 146
if re.search(u"^User '(.*)' was not found in the system\.", error, re.U):
SyntaxError: invalid syntax
Any ideas? I am running this with py32

It looks very much like a bug.
They are claiming python 3 support, but there are u strings in the source code. Python 3 doesn't support u strings, all of the strings are unicode.
Consider submitting an issue to the python-jira bug tracker.

I guess you already installed Jira in your CMD, like:
$ pip install jira
Then just try something like the following:
from jira import JIRA
jira = JIRA('https://jira.atlassian.com') #Project URL
issue = jira.issue('KEY-1')
print issue.fields.project.key # 'KEY'
print issue.fields.summary # 'Issue Summary'

Related

Python code failing to execute Json.Dump after upgrading from 2.7 to 3.10

To preface, this is not my code and am just trying to resolve it. I am not accustomed to Python (just have been introduced with it recently with this project)
We run python scripts via UiPath. We upgraded the version of all python dependencies to Py3.10 which meant I had to convert the scripts using 2to3 as well, I've pinpointed the issue but I don't have any idea why this part of the script would fail.
Debugging technique used - slip ctypes.windll.user32.MessageBoxW in between lines of the script.
Here's the part of the code that was no longer able to show the message box (which I assumed is where this problematic). Line formatted as bold.
dObj = open(param_response_result_file)
ogdata = json.load(dObj)
ogdata['results']['fields'] = field_value_dictionary
with open(param_response_result_file, 'w+') as outfile:
**json.dump(ogdata, outfile)**
outfile.write("\n")
What can be the root causes for this line to fail? I've checked param_response_result_file and it contains the correct values, what more can I check to trace why this json.dump is failing?
Thank you
EDIT I found the exception being thrown:
Object of type bytes is not JSON serializable
How do I resolve this? I am aware that there has been variable changes between Py 2 to 3 upgrade with json instantiations, but how do I get it to pass the correct variable?

Using pyobjc-framework-Quartz in Python 3

I've installed the library 'pyobjc-framework-Quartz'
pip install pyobjc-framework-Quartz
And in Python2, the following lines work perfectly:
provider = Quartz.CGDataProviderCreateWithFilename(input_file_path)
pdf = Quartz.CGPDFDocumentCreateWithProvider(provider)
But in Python3, I get the error message:
provider = Quartz.CGDataProviderCreateWithFilename(input_file_path)
ValueError: depythonifying 'char', got 'str' of 1
I've tried converting to char*
from ctypes import *
path = c_char_p(input_file_path)
but nothing seems to work. Can someone explain the error?
Thanks,
Ryan
I've worked it out. The problem is that the string input_file_path in python3 is a Unicode string, and needs to be converted to a binary string before use in objc APIs.
input_file_path_converted = input_file_path.encode('utf-8')
provider = Quartz.CGDataProviderCreateWithFilename(input_file_path_converted)
.
(Except that it only work for filenames with standard "ASCII" range alphanumerics...)

Using a python2 library with python3

I'm using python3 and geolite2, but I'm finding that I cannot pass in the IP address that I want to look up and I get the following error. I have tried converting to utf-8 and encoding, but am getting the same error.
from geoip import geolite2
ip_address = request.access_route[0] or request.remote_addr
print(">>>", ip_address)
ip_bytes = ip_address.encode('utf-8')
loc = geolite2.lookup(ip_bytes)
or
loc = geolite2.lookup(ip_address.encode())
Following error:
TypeError: 'str' does not support the buffer interface
What format should the IP go in as. In the original doc, it is string.
http://pythonhosted.org/python-geoip/
I would suggest trying the official Python geoip2 API or python-geoip-yplan. The latter is a fork of python-geoip with better Python 3 support.

Syntax Issue in Python urllib2?

Am trying to test out urllib2. Here's my code:
import urllib2
response = urllib2.urlopen('http://pythonforbeginners.com/')
print response.info()
html = response.read()
response.close()
When I run it, I get:
Syntax Error: invalid syntax. Carrot points to line 3 (the print line). Any idea what's going on here? I'm just trying to follow a tutorial and this is the first thing they do...
Thanks,
Mariogs
In Python3 print is a function. Therefore it needs parentheses around its argument:
print(response.info())
In Python2, print is a statement, and hence does not require parentheses.
After correcting the SyntaxError, as alecxe points out, you'll probably encounter an ImportError next. That is because the Python2 module called urllib2 was renamed to urllib.request in Python3. So you'll need to change it to
import urllib.request as request
response = request.urlopen('http://pythonforbeginners.com/')
As you can see, the tutorial you are reading is meant for Python2. You might want to find a Python3 tutorial or Python3 urllib HOWTO to avoid running into more of these problems.

Trying to convert php to python and getting a syntax error

I'm trying to convert some php code into python and am using curl. I've gotten most of it to be accepted, but when it gets to the result = pycurl.exec(Moe) it keeps throwing a syntax error. I guess that I'm not filling out the exec field correctly, but I can't seem to figure out where it is going wrong.
from urllib2 import urlopen
from ClientForm import ParseResponse
import cgi, cgitb
import webbrowser
import curl, pycurl
Moe = pycurl.Curl(wsdl)
Moe.setopt(pycurl.POST, 1)
Moe.setopt(pycurl.HTTPHEADER, ["Content-Type: text/xml"])
Moe.setopt(pycurl.HTTPAUTH, pycurl.BASIC)
Moe.setopt(pycurl.USERPWD, "userid:password")
Moe.setopt(pycurl.POSTFIELDS, Larry)
Moe.setopt(pycurl.SSL_VERIFYPEER, 0)
Moe.setopt(pycurl.SSLCERT, pemlocation)
Moe.setopt(pycurl.SSLKEY, keylocation)
Moe.setopt(pycurl.SSLKEYPASSWD, keypassword)
Moe.setopt(pycurl.RETURNTRANSFER, 1)
result = pycurl.exec(Moe)
pycurl.close(Moe)
Use result = Moe.perform() to execute your request.
PS:
Moe.setopt(pycurl.POSTFIELDS, Larry)
Is Larry actually a variable? If it's a string, quote it.
exec is a reserved word in Python, you cannot have a function of that name. Try reading the pycurl documentation to see what function you should be calling.
I haven't used pycurl myself, but maybe you want to call Moe.perform()?

Categories

Resources