SSLCertVerificationError in jupiter notebook - python-3.9

from urllib.request import urlopen
html = urlopen('http://pythonscraping.com/pages/page1.html')
print(html.read())
this code i have run but still im getting error i have tried to install openssl packages and upgrade certifi

The reason you got error is the cert of that website expired. Below is a suggested solution:
import urllib
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
html=urlopen("https://pythonscraping.com/pages/page1.html", context=ctx)
print(html.read())

Related

Hello everyone, I'm not understanding why import java.io.bufferedReader does not work

Here is the error that I'm getting. There is anyone that has same problem?
Configuring package and writing import java.io.BufferedReader.

cannot import name 'spawn' from 'pexpect' on windows

Trying to ssh tunnel from Windows system through linux jumphost with ip (xx.xx.xx.xx) and connect to target config windows system with ip 127.0.0.1
import sys
import paramiko
import subprocess
import pexpect
from pexpect.popen_spawn import PopenSpawn
import winpexpect
from winpexpect.winspawn import winspawn
child = winpexpect.winspawn('ssh -L 22:xx.xx.xx.xx:4022 Administrator#127.0.0.1 -o StrictHostKeyChecking=no')
child.expect('127.0.0.1')
child.sendline('password')
The above program throws below error when run on Windows system.
File "C:\Python38\lib\site-packages\winpexpect.py", line 18, in
from pexpect import spawn, ExceptionPexpect, EOF, TIMEOUT
ImportError: cannot import name 'spawn' from 'pexpect' (C:\Python38\lib\site-packages\pexpect_init_.py)
cannot import name 'spawn' from 'pexpect' spawn is not for Windows system. use pexpect.popen_spawn.PopenSpawn for windows. check here https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows

Django Rest Framework AttributeError: module 'coreapi' has no attribute 'Client'

I am trying to run tests for api that worked before. Test.py looks like following:
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
class ApiUserTest(APITestCase):
"""
python manage.py test .\apps\api\api_user
API urls:
api_user/login/
api_user/logout/
api_user/register/
api_user/change_password/
"""
def setUp(self):
...
def test_user_register(self):
...
But I'm getting the following error
PS F:\ComputerShop> python manage.py test .\apps\api\api_user
System check identified no issues (0 silenced).
E
======================================================================
ERROR: api.api_user.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: api.api_user.tests
Traceback (most recent call last):
File "C:\Users\Emil\AppData\Local\Programs\Python\Python38\lib\unittest\loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "C:\Users\Emil\AppData\Local\Programs\Python\Python38\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
File "F:\ComputerShop\apps\api\api_user\tests.py", line 3, in <module>
from rest_framework.test import APITestCase
File "F:\ComputerShop\env\lib\site-packages\rest_framework\test.py", line 123, in <module>
class CoreAPIClient(coreapi.Client):
AttributeError: module 'coreapi' has no attribute 'Client'
I also tried to run tests on a known working project, but they did not start there either.
I've tried to reinstalling the rest framework but it doesn't help. I use virtual environment in the project
To solve this problem you should install next packages:
pip install coreapi pyyaml

Databricks error while reading GTiff file using RasterIO

While reading raster file in Databricks getting below error:
ConnectException: Connection refused (Connection refused)
Error while obtaining a new communication channel
Code:
import rasterio
import rasterio.plot
import pyproj
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import rasterio.features
import rasterio.warp
raster = rasterio.open('/dbfs/mnt/Firescar/cvmsre_201909_afka2.tif')
raster.read(1)

Install libraries in OpenShift

I've started to use openshift (free account), successing with python. But I need to install some libraries (requests and others). How to do it? I can't find any docs on it...
Forum's info is obscure... I've followed this thread (for third party libs):
Setup.py
from setuptools import setup
setup(name='Igor YourAppName',
version='1.0',
description='OpenShift App',
author='Igor Savinkin',
author_email='igor.savinkin#gmail.com',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['requests>=2.0.0'],
)
WSGI.py
def application(environ, start_response):
ctype = 'text/plain'
if environ['PATH_INFO'] == '/health':
response_body = "1"
elif environ['PATH_INFO'] == '/env':
response_body = ['%s: %s' % (key, value)
for key, value in sorted(environ.items())]
response_body = '\n'.join(response_body)
else:
ctype = 'text/html'
import requests
see the last line, where I try to import requests.
This yields in 500 error:
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
Custom python package try
My second try was on this thread:
I've created libs directory in my root dir; then added into wsgi.py:
sys.path.append(os.path.join(os.getenv("OPENSHIFT_REPO_DIR"), "libs"))
and cloned requests into that directory. When I do:
C:\Users\Igor\mypythonapp\libs\requests\requests>git ls-files -c
I get the full list of requests package files... but again, result is 500 error.
You should try reading through this section (https://developers.openshift.com/en/python-deployment-options.html) of the Developer Portal which describes how to install dependencies for Pythong applications on OpenShift Online
you should use requirements.txt. My requirements.txt is below
admin$ cat requirements.txt
Flask==0.10.1
Requests==2.6.0

Resources