Skip to main content

Posts

Simulate browser to solve https 403 error

As more and more website use https instead of http, we'll encounter 403 error when get content with requests modules. To solve it, the easiest way is simulating browser to access. OS: Debian 9 Python: 3.5.3 Module: requests setup headers as 1st step: headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3)\            AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36'} then add headers as parameter: res = requests.get(xqurl, headers=headers) Below is my example to get stock price in dictionary from a https website: getStockPriceFromXueqiu.py

Linux command to translate DomainName to IP

To translate Domain name to IP address, there are 2 commands in Linux: 1. dig +short [Domain name] eg: $ dig +short google.com 216.58.197.142 2. nslookup [Domain name] eg:$ nslookup google.com Server:         172.31.0.2 Address:        172.31.0.2#53 Non-authoritative answer: Name:   google.com Address: 172.217.26.14

speedometer: How to check Internet Speed via Terminal?

To check server current Internet speed, not the max speed in terminal/command line, the easiest way is speedometer. Take Ubuntu as example: Install: $ sudo apt install speedometer Usage: $ speedometer -rx eth0 unit conversion: bit=bit B=byte 1 byte=8 bit bps=bit/s MB/S = megabyte per second MiB/s = mebibyte per second 1 meibyte=2**20=1048576 bytes = 1024 kibibytes 1 Mbps=1 Mbit/s = 0.125MB/s =(0.125M/2**20)= 0.1192 MiB/s

Show Caps Lock indicator in Debian

For laptop who lacks of Caps Lock indicator, it's headache to check the button again and again. So, adapt a plugin should be a good idea. For Debian, I select indicator-keylock who was designed for Ubuntu although. You can find details here . Download .deb file on the right side. Right click to install with GDebi Package Installer, then logout to active it as following: Indicator for Lock Keys: An appindicator for showing the status of the keyboard lock keys, including Caps Lock, Num Lock and Scroll Lock. 

Setup Python Environment in Atom

If Atom is your preference text editor and Python 3 is one of your programming language, the blog is for you. It'll show you how to setup Python environment in Atom: edit and run. OS                 : Debian 9 Python          : 3.5 Atom version: 1.16.0 Atom Plugin :  atom-runner & autosave the 1st step is Atom installation, I think it should be done on your PC, otherwise, download .deb file from Atom website  and install it in terminal as following: sudo dpkg -i atom-amd64.deb If problem, fix it with: sudo apt-get install -f  The 2nd step is adjust configuration. Open Atom, select 'Edit'-->'Preferences'-->'Editor': Tick 'Show Indent Guide' Change 'Tab Length' to '4' The 3nd one is adding ' atom-runner ' and 'autosave' plugin. Click 'Packages' under 'Preferences' in above step, then search and install 'atom-runner' and 'autosave'. For 'autosave', clic...

-bash: python: command not found

OS: Debian 9 Python: 3.5.3 Title error encountered when I add ' #! python3 ' in .py file as 1st line. Seems lost the path. As I installed python 3 already, so check its path with 'which' command: peter@Debian:~$ which python3 /usr/bin/python3 Then replace it with absolute path '#! /usr/bin/python3'. Pass!