Search This Blog

Showing posts with label py. Show all posts
Showing posts with label py. Show all posts

Sunday, April 12, 2020

Python Flask AttributeError: 'Request' object has no attribute 'is_xhr'

#. Remove flask and install recent version

    pip uninstall flask
    pip intall flask


#. Else, go to your requirements.txt remove the verions of your plugins/libraries.
   ex: flask=0.12.0
          to
         flask


Re run the requriements.txt and make sure all it is now in updated version.
#before uninstall manually and run the below command.

pip install -r requirements.txt


Tuesday, September 24, 2019

Python - Map Nested Map

Input

[{
"groupId": "a1",
"orderId": "b1"
}, {
"groupId": "a2",
"orderId": "b2"
}, {
"groupId": "a2",
"orderId": "b3"
}]

Output 
{
'a1': {
'b1': {
'groupId': 'a1',
'orderId': 'b1'
}
},
'a2': {
'b2': {
'groupId': 'a2',
'orderId': 'b2'
},
'b3': {
'groupId': 'a2',
'orderId': 'b3'
}
}
}


Code

data = [{"groupId":"a1","orderId":"b1"},{"groupId":"a2","orderId":"b2"}, {"groupId":"a2","orderId":"b3"}]

groupMap = {}


for x in data:
    if ( helpers.isKeyExists (groupMap, x['groupId']) == False ):
        orderMap = {}
        orderMap[x['orderId']] = x;
        groupMap[x['groupId']] = orderMap;
    else:
        tempOrderMap = {}
        #if ( helpers.isKeyExists (orderMap, x['groupId']) == False ):
        tempOrderMap = groupMap[x['groupId']]
        tempOrderMap[x['orderId']] = x;
        groupMap[x['groupId']] = tempOrderMap;
       

print (groupMap);


Thursday, August 22, 2019

Install Python 3.x 3.7 in Ubuntu 18 from Bundle

Steps

1.   Donwload the tar - Python-3.7.4.tar.xz
2.  cd /home/ubuntu/
3.  tar xf Python-3.7.4.tar.xz
4   chmod 775 Python-3.7.4
5   chown -R root Python-3.7.4
6   chown -R root Python-3.7.4
7   cd Python-3.7.4/
8   ./configure
9   ./configure --enable-optimizations
10  make
11  make test
12  sudo make install
13  python3 --version
14  pip3
15  which python3


Your Sample Rest Application
1  cd /opt/stock/stockautobot
2  pip3 install -r requirements.txt
3  python3 app.py


Any package/module missed. please use below command to add
1  pip3 install requests


RUN
1 wget http://127.0.0.1:5002/
2 curl http://localhost:5002/


Hit Counter


View My Stats