Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

403 Forbidden errors when request a webpage using Python requests

Error 

403 Forbidden errors when request a web page using Python requests. 


Cause

Usually, this is caused by the lack of headers indicating User-Agent. We can add the header information with User-Agent and send the request again.

import requests

url = 'http://example.com/'

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}

result = requests.get(url, headers=headers)
# Check the status code 
print(result.status_code)

Tensorflow Error - TypeError: bases must be types





It worked just fine for me. Tensorflow and protobuf versions are incompatible in my case.

pip uninstall protobuf
pip install protobuf==3.20.1
Source: https://stackoverflow.com/questions/72779449/google-visions-python-client-quickstart-throws-typeerror-bases-must-be-types

Pip install Read timed out error

Error: pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out 

Reasons:

  • the network speed is slow, which caused by instability
  • the default installation source for some libraries is pip the default source is pypi.python.org, if the server that installs the source is not in the country, it will be restricted

Solutions:(https://www.codestudyblog.com/cs2112pyb/1214135027.html)

1 change settings pip installation extension time
  • pip --default-timeout=100 install -U  library name 

2 change the mirror image

replace the use of domestic images during pip installation , general use of tsinghua university 、 these two images of douban

tsinghua mirror image :

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  library name 
douban image :

pip install -i http://pypi.douban.com/simple  library name 
  domestic commonly used mirror images


3 set up proxy

pip installation by setting up an agent

pip install --proxy  proxy library name 

for example :
pip install -i http://pypi.douban.com/simple  --proxy http://10.22.96.13:8008 jupyter


4 modify pip change the source of the configuration file

by modifying the pip configuration , to change the default source to a domestic one, we only need the simplest command. "pip config set global.index-url source link " that's it. for example, replace it with tsinghua source. :

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

ImportError: No module named 'numpy.core.multiarray\r'

Error: ImportError: No module named 'numpy.core.multiarray when: loading a pickle file

pickle.load(open('cluster/user_dict','r'))

Resolution:

pickle.load(open('cluster/user_dict','rb'), encoding='latin-1')

MySQL - Does not support LIMIT in IN/ALL/ANY/SOME subquery: Error Code 1235

           UPDATE aboutme.RandomSample SET TestFlag = 1 WHERE UGCID in  
           (SELECT UGCID FROM   
                (SELECT UGCID FROM aboutme.RandomSample WHERE TwitterURI = @twitter_uri ORDER BY RAND() LIMIT 10) tmp  
           );  

Error : The entity “nbsp” was referenced, but not declared

Error : The entity “nbsp” was referenced, but not declared while parsing RDFa using Semalgl parser.


Solution : Using &#160 instead of &nbsp