Hello! I am trying to create a very simple script that creates a new user. I have been following the Jira Cloud platform REST API documentation
and copied the Create user script for Python. When I try running it, I receive the following error:
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/opt/anaconda3/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/anaconda3/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I'm not quite sure what I am doing wrong. The only portion of the script I'm really changing are the URL, email addresses, and API tokens. Any and all help is greatly appreciated!
Hi @Luke Simon
Welcome to Atlassian community!
Is it possible to post your code here? I know that you mentioned the article and the example provided there in, but just wanted to check it out.
Did you try checking out the curl example using the tool like Postman?
Thanks,
Vamsi
I have not tried the curl example, no.
Here is my code:
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://mycompanynamehere.atlassian.net/rest/api/3/user"
auth = HTTPBasicAuth("username@username.com", "APIKEY")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps( {
"emailAddress": "testuser@testuser.com"
} )
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Luke Simon
I used the same exact code after updating the details for my Cloud Jira url and authentication. It worked for me and created the user successfully.
So, it is not related to the code and must be missing some libraries.
Are you using any application like PyCharm or anything and executing your code? I just created the 'test.py' file and executed that in CLI directly like 'python test.py'.
Can you try updating Python to the latest version if it is not already updated and also try updating the GUI software if you are using one (like PyCharm)?
Thanks,
Vamsi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am on MacOS and using python via terminal. It is updated to the newest version, so I'm not sure what I am doing wrong either!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've got the same issue, latest version of Python on windows and following https://confluence.atlassian.com/jirakb/how-to-bulk-create-users-in-jira-1129691096.html
From what I've read it's seeing an invalid json file, but the syntax in the .py script looks correct?
Traceback (most recent call last):
File "C:\Temp\bulkuser.py", line 35, in <module>
print(json.dumps(json.loads(response.text), sort_keys=True, separators=(",", ": ")))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.