I have spent the last few months running neo4j on my local machine. I have been using py2neo to orchestrate the db with python. I have just switched to running the database on an aws ec2 instance and I am recieving errors whenever I try to send requests to the database.
I am using the following simple code to test the database, this code works perfectly on my local machine.
from py2neo import *
neo4j_url = 'http://localhost:7474/'
user = 'neo4j'
pwd = 'neo4j'
graph = Graph(neo4j_url, auth=(user,pwd))
print(graph)
graph.run("Create (n:Person{name: 'Andy person'})")
This code errors with
Graph('http://localhost:7474')
Traceback (most recent call last):
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/client/http.py", line 443, in from_json
content = json_loads(data, object_hook=JSONHydrant.json_to_packstream)
File "/usr/lib64/python3.8/json/__init__.py", line 370, in loads
return cls(**kw).decode(s)
File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/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)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_connection.py", line 9, in <module>
graph.run("Create (n:Person{name: 'Andy person'})")
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/database.py", line 405, in run
return self.auto().run(cypher, parameters, **kwparameters)
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/database.py", line 989, in run
result = self._connector.auto_run(cypher, parameters,
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/client/__init__.py", line 1340, in auto_run
return cx.auto_run(cypher, parameters, graph_name=graph_name, readonly=readonly)
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/client/http.py", line 177, in auto_run
rs = HTTPResponse.from_json(r.status, r.data.decode("utf-8"))
File "/home/ec2-user/KG_construction/kg-construction/KG_env/lib64/python3.8/site-packages/py2neo/client/http.py", line 445, in from_json
raise_from(ProtocolError("Cannot decode response content as JSON"), error)
File "<string>", line 3, in raise_from
py2neo.errors.ProtocolError: Cannot decode response content as JSON
Does anyone have idea why this error is occuring on my ec2 instance but not on my local machine?
Related
am working on a kivy app that uses a threaded socket server,to send and recieve message from a database, when i use json in my code to load data that just short, such as the sql statement below that selects just a target person from a database, i get no errors
import json
import sqlite3
conn = sqlite3.connect("DataBase.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM Profile WHERE Username='williz'",)
rows=cursor.fetchall()
conn.commit()
conn.close()
list_ = []
for i in rows:
list_.append(i)
m = str.encode(json.dumps(list_))
print(m)
But when i change this same code sql statement, to select much more data such as ("SELECT * FROM Profile"), i get the error
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:/Users/User/PycharmProjects/MyProject1/schoolproject/new.py", line 148, in run
command = json.loads(command)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\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)
This only happens just as the data am trying to get gets larger, and i really dont know a way around it
I'm trying to execute Overpass queries from a Python script. I'm practicing at overpass-turbo.eu and found the following query to work as intended:
[out:json][timeout:600];
{{geocodeArea:Niedersachsen}}->.searchArea;
(
node[place=city](area.searchArea);
node[place=town](area.searchArea);
);
out;
However, when I submit the exact same query from a Python script, I get an error:
import requests
overpass_query = """
[out:json][timeout:600];
{{geocodeArea:Niedersachsen}}->.searchArea;
(
node[place=city](area.searchArea);
node[place=town](area.searchArea);
);
out;
"""
overpass_url = "http://overpass-api.de/api/interpreter"
response = requests.get(overpass_url, params={'data': overpass_query})
data = response.json()
/home/enno/events/docker/etl/venv/bin/python /home/enno/events/docker/etl/test2.py
Traceback (most recent call last):
File "/home/enno/events/docker/etl/test2.py", line 16, in <module>
data = response.json()
File "/home/enno/events/docker/etl/venv/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Process finished with exit code 1
Why is this? It seems to have to do with the curly braces, but I can't figure out how to solve this.
Many thanks,
Enno
The curly braces (aka {{geocodeArea:Niedersachsen}}) are a special feature of overpass turbo and are not part of Overpass API. See extended overpass turbo queries for a list of these shortcuts.
{{geocodeArea:name}} will tell overpass turbo to perform a geocoding request using Nominatim. It will then use the first result to construct an area(id) query. You have to perform the same step (using Nominatim or any other geocoder) in your program.
I am trying to import Quandl data using the following instruction:
quandl.get('WIKI/GOOGL')
The following error getting popped out:
Traceback (most recent call last):
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 55, in parse
return response.json()
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/requests/models.py", line 850, in json
return complexjson.loads(self.text, **kwargs)
File "/home/shravilp/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/home/shravilp/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/shravilp/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ml1.py", line 4, in <module>
df = quandl.get('WIKI/GOOGL')
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 61, in handle_api_error
error_body = cls.parse(resp)
File "/home/shravilp/anaconda3/lib/python3.6/site-packages/quandl/connection.py", line 57, in parse
raise QuandlError(http_status=response.status_code, http_body=response.text)
quandl.errors.quandl_error.QuandlError: (Status 403) Something went wrong. Please try again. If you continue to have problems, please contact us.
Following is my code:
import pandas as pd
import quandl
df = quandl.get("FRED/GDP")
print(df.head())
An error 403, as stated on the Quandl API docs states that you need an API key to access that. Here are the steps to rectify it-
1.Create a free/premium account on Quandl.
2.Generate an API key from account settings options.
3.Include your API key in the script as, quandl.ApiConfig.api_key = "YOURAPIKEY".
Create account get api key and add this
quandl.ApiConfig.api_key = "#######"
df = quandl.get("FRED/GDP")
print(df.head())
generate a new key
I got a program from a formerly colleague and now should maintain it.
This python script asks our Jira instance with a given jql ( on the API ).
The return is a list of all issues, which are matching the search criteria.
But now it's not working, and I receive on the server ( Ubuntu ) and on my local windows PC a Json error message.
note : it ran for about a year not, but back then it worked.
Here is what the script looks like :
import json
import subprocess
jiraSerachUrl = "https://ourJiraInstance.net/rest/api/2/search?jql=key%20=%20%22TEST-123%22"
jiraResponse = subprocess.Popen(["curl","-l","-s","-u", "jiraUser"+":"+"jiraUserPassword", "-X", "GET", jiraSerachUrl ],stdout=subprocess.PIPE,shell=True).communicate()[0]
## shell=True only added for Windows Instance
print(type(jiraResponse))
##print = <class 'bytes'>
print(jiraResponse)
## print = b''
jiraJsonResponse = json.loads(jiraResponse.decode('utf-8'))
print(jiraJsonResponse)
The jql/jira search address returns the following (shorted answer, all fields of the task are returned):
{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":
[{"expand":"operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields",
"id":"145936","self":"https://ourJiraInstance.net/rest/api/2/issue/145936","key":"TEST-123","fields":{"parent": ...
The Error on the Windows PC is the following
Traceback (most recent call last): File
"C:\Users\User\Desktop\test.py", line 10, in
jiraJsonResponse = json.loads(jiraResponse.decode('utf-8')) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json__init__.py",
line 319, in loads
return _default_decoder.decode(s) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py",
line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py",
line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0)
This is the error on the Ubuntu Server ( running the same script )
Traceback (most recent call last): File "searchJira.py", line 33, in
jiraJsonResponse = json.loads(jiraResponse) File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
So far I tried to change the Json load to simpleJson, but with the same result.
Changing the format to which Json should decode ( e.g. unicode ) took no effect.
I have tried a bit and finaly got it. by replacing curl with responses i got finally the result I wanted. my request looks now like this :
r = requests.get(jiraSerachUrl,auth=HTTPBasicAuth(user, password), verify=False)
jiraJsonResponse=json.loads(r.text)
I want to create issue on JIRA using python, so I am learning the way on Welcome to jira-python's documentation.
But then the first question puzzles me. What is the server if we are using our own JIRA? On this documentation, it uses https://jira.atlassian.com. If I am using JIRA whose url is like: https://bugs.company.com/secure/Dashboard.jspa. What is the server for me?
Now, I am using
jira = JIRA(options={'server': 'https://bugs.company.com'})
projects = jira.projects()
keys = [project.key for project in projects]
I will get the error:
Traceback (most recent call last):
File "MethodTest.py", line 9, in <module>
projects = jira.projects()
File "/Library/Python/2.7/site-packages/jira/client.py", line 838, in projects
r_json = self._get_json('project')
File "/Library/Python/2.7/site-packages/jira/client.py", line 1423, in _get_json
r_json = json.loads(r.text)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
The problems might comes from the fact that you are using a secure connection to your jira instance. You need to setup a proper certificate for your connection or simply disable certificate verification.
See jira.client.JIRA options and set verify to False as such:
jira = JIRA(options={'server': 'https://bugs.company.com',
'verify': False})
Are you setting the proper username and password?
Finally, you might want to check with your IT department for the proper url.