Connecting database server and creating csv file using SSHTunnel
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am getting this error everytime I try to connect with the server.
BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
def make_JSON_creds(filename="./.usercreds.json"):
"""Creates a JSON credentials file with name <filename>"""
# Get keys (without them showing up on screen)
print("Enter the following credentials:")
SSH_USERNAME = getpass("SSH USERNAME")
SSH_PRIVATE_KEY = getpass("SSH PASSWORD")
DB_USERNAME = getpass("DATABASE ACCESS USERNAME")
DB_PASSWORD = getpass("DATABASE ACCESS PASSWORD")
# Write to file. TODO: Encrypt this.
with open(filename, "w") as the_file:
json.dump({"SSH_USERNAME" : SSH_USERNAME,
"SSH_PRIVATE_KEY" : SSH_PRIVATE_KEY,
"DB_USERNAME" : DB_USERNAME,
"DB_PASSWORD" : DB_PASSWORD}, the_file)
def get_JSON_creds(filename="./.usercreds.json", ask=True):
"""Loads JSON credentials from a credentials file.
Creates the file if it doesn't exist.
Returns an OAuth1 header object.
"""
# Make the file if it isn't there. Or if you just want to.
if ask or not os.path.isfile(filename): # Note: This is technically unsafe
make_JSON_creds(filename)
# Then it's there. Get it.
with open(filename, "r") as the_file:
creds = json.load(the_file)
return(creds)
#SSH tunnelling with port forwarding to database server
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password=ssh_private_key,
remote_bind_address=(localhost, 3306),
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
creds = get_JSON_creds(filename="./.usercreds_tide.json", ask=True)
# ssh variables
host = 'Hostname'
localhost = '127.0.0.1'
ssh_username = creds.get("SSH_USERNAME").strip()
ssh_private_key = creds.get("SSH_PRIVATE_KEY").strip()
# database variables
user=creds.get("DB_USERNAME").strip()
password=creds.get("DB_PASSWORD").strip()
database='tidal'
df = query("SELECT comm.Art,comm.Text,COUNT(comm.Text),
comm.Info,commurl.Title,commurl.Source FROM comm INNER JOIN commurl ON
comm.Id=commurl.ID GROUP BY Id HAVING COUNT(comm.Text)>100")
The error is:
2018-11-16 23:10:01,480| ERROR | Could not connect to gateway lrs-abc.pqr.sot.in:22 : 10060
BaseSSHTunnelForwarderError Traceback (most recent call last)
json sql-server connection database-connection ssh-tunnel
add a comment |
I am getting this error everytime I try to connect with the server.
BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
def make_JSON_creds(filename="./.usercreds.json"):
"""Creates a JSON credentials file with name <filename>"""
# Get keys (without them showing up on screen)
print("Enter the following credentials:")
SSH_USERNAME = getpass("SSH USERNAME")
SSH_PRIVATE_KEY = getpass("SSH PASSWORD")
DB_USERNAME = getpass("DATABASE ACCESS USERNAME")
DB_PASSWORD = getpass("DATABASE ACCESS PASSWORD")
# Write to file. TODO: Encrypt this.
with open(filename, "w") as the_file:
json.dump({"SSH_USERNAME" : SSH_USERNAME,
"SSH_PRIVATE_KEY" : SSH_PRIVATE_KEY,
"DB_USERNAME" : DB_USERNAME,
"DB_PASSWORD" : DB_PASSWORD}, the_file)
def get_JSON_creds(filename="./.usercreds.json", ask=True):
"""Loads JSON credentials from a credentials file.
Creates the file if it doesn't exist.
Returns an OAuth1 header object.
"""
# Make the file if it isn't there. Or if you just want to.
if ask or not os.path.isfile(filename): # Note: This is technically unsafe
make_JSON_creds(filename)
# Then it's there. Get it.
with open(filename, "r") as the_file:
creds = json.load(the_file)
return(creds)
#SSH tunnelling with port forwarding to database server
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password=ssh_private_key,
remote_bind_address=(localhost, 3306),
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
creds = get_JSON_creds(filename="./.usercreds_tide.json", ask=True)
# ssh variables
host = 'Hostname'
localhost = '127.0.0.1'
ssh_username = creds.get("SSH_USERNAME").strip()
ssh_private_key = creds.get("SSH_PRIVATE_KEY").strip()
# database variables
user=creds.get("DB_USERNAME").strip()
password=creds.get("DB_PASSWORD").strip()
database='tidal'
df = query("SELECT comm.Art,comm.Text,COUNT(comm.Text),
comm.Info,commurl.Title,commurl.Source FROM comm INNER JOIN commurl ON
comm.Id=commurl.ID GROUP BY Id HAVING COUNT(comm.Text)>100")
The error is:
2018-11-16 23:10:01,480| ERROR | Could not connect to gateway lrs-abc.pqr.sot.in:22 : 10060
BaseSSHTunnelForwarderError Traceback (most recent call last)
json sql-server connection database-connection ssh-tunnel
add a comment |
I am getting this error everytime I try to connect with the server.
BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
def make_JSON_creds(filename="./.usercreds.json"):
"""Creates a JSON credentials file with name <filename>"""
# Get keys (without them showing up on screen)
print("Enter the following credentials:")
SSH_USERNAME = getpass("SSH USERNAME")
SSH_PRIVATE_KEY = getpass("SSH PASSWORD")
DB_USERNAME = getpass("DATABASE ACCESS USERNAME")
DB_PASSWORD = getpass("DATABASE ACCESS PASSWORD")
# Write to file. TODO: Encrypt this.
with open(filename, "w") as the_file:
json.dump({"SSH_USERNAME" : SSH_USERNAME,
"SSH_PRIVATE_KEY" : SSH_PRIVATE_KEY,
"DB_USERNAME" : DB_USERNAME,
"DB_PASSWORD" : DB_PASSWORD}, the_file)
def get_JSON_creds(filename="./.usercreds.json", ask=True):
"""Loads JSON credentials from a credentials file.
Creates the file if it doesn't exist.
Returns an OAuth1 header object.
"""
# Make the file if it isn't there. Or if you just want to.
if ask or not os.path.isfile(filename): # Note: This is technically unsafe
make_JSON_creds(filename)
# Then it's there. Get it.
with open(filename, "r") as the_file:
creds = json.load(the_file)
return(creds)
#SSH tunnelling with port forwarding to database server
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password=ssh_private_key,
remote_bind_address=(localhost, 3306),
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
creds = get_JSON_creds(filename="./.usercreds_tide.json", ask=True)
# ssh variables
host = 'Hostname'
localhost = '127.0.0.1'
ssh_username = creds.get("SSH_USERNAME").strip()
ssh_private_key = creds.get("SSH_PRIVATE_KEY").strip()
# database variables
user=creds.get("DB_USERNAME").strip()
password=creds.get("DB_PASSWORD").strip()
database='tidal'
df = query("SELECT comm.Art,comm.Text,COUNT(comm.Text),
comm.Info,commurl.Title,commurl.Source FROM comm INNER JOIN commurl ON
comm.Id=commurl.ID GROUP BY Id HAVING COUNT(comm.Text)>100")
The error is:
2018-11-16 23:10:01,480| ERROR | Could not connect to gateway lrs-abc.pqr.sot.in:22 : 10060
BaseSSHTunnelForwarderError Traceback (most recent call last)
json sql-server connection database-connection ssh-tunnel
I am getting this error everytime I try to connect with the server.
BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
def make_JSON_creds(filename="./.usercreds.json"):
"""Creates a JSON credentials file with name <filename>"""
# Get keys (without them showing up on screen)
print("Enter the following credentials:")
SSH_USERNAME = getpass("SSH USERNAME")
SSH_PRIVATE_KEY = getpass("SSH PASSWORD")
DB_USERNAME = getpass("DATABASE ACCESS USERNAME")
DB_PASSWORD = getpass("DATABASE ACCESS PASSWORD")
# Write to file. TODO: Encrypt this.
with open(filename, "w") as the_file:
json.dump({"SSH_USERNAME" : SSH_USERNAME,
"SSH_PRIVATE_KEY" : SSH_PRIVATE_KEY,
"DB_USERNAME" : DB_USERNAME,
"DB_PASSWORD" : DB_PASSWORD}, the_file)
def get_JSON_creds(filename="./.usercreds.json", ask=True):
"""Loads JSON credentials from a credentials file.
Creates the file if it doesn't exist.
Returns an OAuth1 header object.
"""
# Make the file if it isn't there. Or if you just want to.
if ask or not os.path.isfile(filename): # Note: This is technically unsafe
make_JSON_creds(filename)
# Then it's there. Get it.
with open(filename, "r") as the_file:
creds = json.load(the_file)
return(creds)
#SSH tunnelling with port forwarding to database server
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password=ssh_private_key,
remote_bind_address=(localhost, 3306),
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
creds = get_JSON_creds(filename="./.usercreds_tide.json", ask=True)
# ssh variables
host = 'Hostname'
localhost = '127.0.0.1'
ssh_username = creds.get("SSH_USERNAME").strip()
ssh_private_key = creds.get("SSH_PRIVATE_KEY").strip()
# database variables
user=creds.get("DB_USERNAME").strip()
password=creds.get("DB_PASSWORD").strip()
database='tidal'
df = query("SELECT comm.Art,comm.Text,COUNT(comm.Text),
comm.Info,commurl.Title,commurl.Source FROM comm INNER JOIN commurl ON
comm.Id=commurl.ID GROUP BY Id HAVING COUNT(comm.Text)>100")
The error is:
2018-11-16 23:10:01,480| ERROR | Could not connect to gateway lrs-abc.pqr.sot.in:22 : 10060
BaseSSHTunnelForwarderError Traceback (most recent call last)
json sql-server connection database-connection ssh-tunnel
json sql-server connection database-connection ssh-tunnel
asked Nov 17 '18 at 4:34
AniAni
62
62
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348245%2fconnecting-database-server-and-creating-csv-file-using-sshtunnel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348245%2fconnecting-database-server-and-creating-csv-file-using-sshtunnel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown