Wednesday, 25 April 2018

POST data to any endpoint via REST API




curl -v -X POST -u "user:password" --header "Content-Type: application/json" 'http://<host>:<port>/<endpoint>' -d @test.json


You can change the Content-Type based on your required type and supported by endpoint.

Type application 
================
application/javascript
application/octet-stream
application/ogg
application/pdf
application/xhtml+xml
application/x-shockwave-flash
application/json
application/ld+json
application/xml
application/zip

Type Audio
==========

audio/mpeg
audio/x-ms-wma
audio/vnd.rn-realaudio
audio/x-wav

Type image
==========

image/gif
image/jpeg
image/png
image/tiff
image/vnd.microsoft.icon
image/x-icon
image/vnd.djvu
image/svg+xml

Wednesday, 11 April 2018

Encode Decode error in python : UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0

Error desc:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0:
                    ordinal not in range(128)

This type of error comes when some special character is not in range of selected encoding type.

Solution :

Find the default encoding type of python.
             python -c 'import sys; print(sys.getdefaultencoding())'
             o/p : ascii

We need to change the encoding type and try with different type of encoding. e.g.

latin-1
utf-8
utf-16-be


Create a file sitecustomize.py under this location : /usr/lib/python2.7/site-packages/sitecustomize.py

echo "import sys; sys.setdefaultencoding('latin-1')" > sitecustomize.py


Compile the python script and check the encoding type is changed by below command.
python -m py_compile sitecustomize.py

PYTHONPATH=".:$PYTHONPATH" python -c 'import sys; print(sys.getdefaultencoding())'

o/p : latin-1

Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...