Friday, 1 January 2021

How to get generic data type from dialect specific type in sqlalchemy?

I want to create a function that maps dialect-specific DB types to generic sqlalchemy DB types.

For example: I'm trying to get data types from the OracleDB table and then create a table in MySql DB(or another) using received metadata. I'm getting dialect-specific column types.

Here is a minimal code to create OracleDB table:

create table test_test(id int, num_int number(10), num_float number(10,4), dt date, ts timestamp, str varchar2(100), fl float);

insert into test_test(id) values(1);

To receive DB table column types

from pprint import pprint
from sqlalchemy import sessionmaker, create_engine

engine = create_engine(...)
session = sessionmaker()
session.configure(bind=engine)
session = session()
res = session.execute('select * from test_test where 1 = 2')
columns = res.cursor.description
pprint(columns)

Output

[('ID', <cx_Oracle.DbType DB_TYPE_NUMBER>, 39, None, 38, 0, 1),
 ('NUM_INT', <cx_Oracle.DbType DB_TYPE_NUMBER>, 11, None, 10, 0, 1),
 ('NUM_FLOAT', <cx_Oracle.DbType DB_TYPE_NUMBER>, 16, None, 10, 4, 1),
 ('DT', <cx_Oracle.DbType DB_TYPE_DATE>, 23, None, None, None, 1),
 ('TS', <cx_Oracle.DbType DB_TYPE_TIMESTAMP>, 23, None, 0, 6, 1),
 ('STR', <cx_Oracle.DbType DB_TYPE_VARCHAR>, 100, 100, None, None, 1),
 ('FL', <cx_Oracle.DbType DB_TYPE_NUMBER>, 127, None, 126, -127, 1)]

How can I get generic sqlalchemy column types (String, Integer, etc) instead of dialect-specific ones?



from How to get generic data type from dialect specific type in sqlalchemy?

Can't connect to local Node.js secure WebSocketServer

For testing a JavaScript / html5 application, I created a local WebSocketServer with node.js and ws package. I want to use secure websockets (wss) with SSL/TLS.

Key and certificate were create for testing purposes by OpenSSL locally (self signed certificate).

The client just tries to use the native WebSocket object to connect to the (local) https Server:

var ws = new Websocket('wss://localhost:8080');

The Problem is, no browser (Firefox, Chrome, Edge) can connect to the server and they all give me different error messages.

Firefox:

Firefox can not connect to the server at wss: // localhost: 8080 /.

Chrome:

ws_client.js:7 WebSocket connection to 'wss://localhost:8080/' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

Edge:

SCRIPT12017: SCRIPT12017: WebSocket Error: SECURITY_ERR, Cross zone connection not allowed

I created the certificate and key in OpenSSL (light, newest version) like this:

openssl req -new -x509 -nodes -out server.crt -keyout server.key

(source)

I checked almost every question about this (and similar) topics, e.g. this question, but none of them could provide a solution.

Please do not mark this question as a duplicate, because all similar questions contain slightly different problems!

Server Code:

var fs = require('file-system');

var pkey = fs.readFileSync('server.key', 'utf8');
var crt = fs.readFileSync('server.crt', 'utf8');

var credentials = { key: pkey, cert: crt };
var https = require('https');

var httpsServer = https.createServer(credentials);
httpsServer.listen(8080);

var WebSocketServer = require('ws').Server;

var wss = new WebSocketServer({
    server: httpsServer
});

wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
        console.log('received: %s', message);
        ws.send('reply from server : ' + message)
    });

});

I tried another code as server, but same errors occur:

const WebSocketServer = require('ws').Server; 
var fs = require('file-system');

var ws_cfg = {
    ssl: true,
    port: 8080,
    ssl_key: 'server.key',
    ssl_cert: 'server.crt'
};

var processRequest = function(req, res) {
    console.log('Request received');
};

var httpServ = require('https');

var app = httpServ.createServer({
    key: fs.readFileSync(ws_cfg.ssl_key, 'utf8', (error) => {
        console.log('Error reading file');
    }),
    cert: fs.readFileSync(ws_cfg.ssl_cert, 'utf8',  (error) => {
        console.log('Error reading file');
    })
}, processRequest).listen(ws_cfg.port, function(){
    console.log('Server running');
});



var wss = new WebSocketServer( {server: app, port: 8080, host: 'localhost', domain: 'localhost'} );



wss.on('connection', function (ws) {

    console.log('Connected to a client');

    ws.on('message', function (message) {

        console.log('MSG received: ' + message);

    });

});

There's one more thing. Always, if I add a console.log(wss); to the server Code, the output looks something like this:

WebSocketServer {
  domain: null,
  ...some more stuff...
  ...cert key etc....
  host: null,
  path: null,
  port: null } }

host, domain and port is set to null. I tried everything to set it to localhost:8080, but nothing worked out. I think this could be the source of all Problems, but can't find a way. If anyone knows an answer to this question, I would highly appreciate it.

(Using the insecure 'ws' protocol ('ws://localhost:8080') in order to connect to local node.js http server works, but I want to test the app as realistic as possible and use a secure Connection.)



from Can't connect to local Node.js secure WebSocketServer

Build apps with travis not supporting multiple locale (Languages)

I am working on the project which support multiple locale (Languages). The app is supporting multiple languages by installing directly it from the Android studio or build app with the Android studio. But when we build the app through the travis, only english language is supported. I have tried by changing multiple supported languages from the phone but it is not working.

What I want to Achieve?

I want to support multiple locale (Languages) which languages string.xml are already available into the project. App build through the travis should support other languages than English when user change the language of the phone.

Note: For this, code and steps to reproduce is not required.

Please let me know if anyone have idea regarding this issue, Thanks.



from Build apps with travis not supporting multiple locale (Languages)