error using pip search (pip search stopped working) - python

I am getting this error in pip search while studying python.
The picture is an error when I pip search. Can you tell me how to fix it?
$ pip search pdbx
ERROR: Exception:
Traceback (most recent call last):
File "*/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 224, in _main
status = self.run(options, args)
File "*/lib/python3.7/site-packages/pip/_internal/commands/search.py", line 62, in run
pypi_hits = self.search(query, options)
File "*/lib/python3.7/site-packages/pip/_internal/commands/search.py", line 82, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/usr/lib/python3.7/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "*/lib/python3.7/site-packages/pip/_internal/network/xmlrpc.py", line 46, in request
return self.parse_response(response.raw)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1342, in parse_response
return u.close()
File "/usr/lib/python3.7/xmlrpc/client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32500: 'RuntimeError: This API has been temporarily disabled due to unmanageable load and will be deprecated in the near future. Please use the Simple or JSON API instead.'>

The pip search command queries PyPI's servers, and PyPI's maintainers have explained that the API endpoint that the pip search command queries is very resource intensive and too expensive for them to always keep open to the public. Consequently they sometimes throttle access and are actually planning to remove it completely soon.
See this GitHub issues thread ...
The solution I am using for now is to pip install pip-search (a utility created by GitHub user #victorgarric).
So, instead of 'pip search', I use pip_search. Definitely beats searching PyPI via a web browser

Follow the suggestion from JRK at the discussion at github (last comment) the search command is temporarily disabled, use your browser to search for packages meanwhile:
Check the thread on github and give him a thumb up ;)

search on website, https://pypi.org/,
then install the package you wanted

The error says
Please use the Simple or JSON API instead
You can try pypi-simple to query the pip repository
https://pypi.org/project/pypi-simple/
It gives an example too, I tried to use it here:
pypi-simple version 0.8.0 DistributionPackage' object has no attribute 'get_digest':
!/usr/bin/env python3
-*- coding: utf-8 -*-
"""
Created on Thu Nov 11 17:40:03 2020
#author: Pietro
"""
from pypi_simple import PyPISimple
def simple():
package=input('\npackage to be checked ')
try:
with PyPISimple() as client:
requests_page = client.get_project_page(package)
except:
print("\n SOMETHING WENT WRONG !!!!! \n\n",
"CHECK INTERNET CONNECTION OR DON'T KNOW WHAT HAPPENED !!!\n")
pkg = requests_page.packages[0]
print(pkg)
print(type(pkg))
print('\n',pkg,'\n')
print('\n'+pkg.filename+'\n')
print('\n'+pkg.url+'\n')
print('\n'+pkg.project+'\n')
print('\n'+pkg.version+'\n')
print('\n'+pkg.package_type+'\n')
#print('\n'+pkg.get_digest()+'\n','ENDs HERE !!!!') #wasnt working
if __name__ == '__main__':
simple()
got -4 so far for this answer don't know why , figureout I can try to check for a package with:
# package_name = input('insert package name : ')
package_name = 'numpy'
import requests
url = ('https://pypi.org/pypi/'+package_name+'/json')
r = requests.get(url)
try:
data = r.json()
for i in data:
if i == 'info':
print('ok')
for j in data[i]:
if j == 'name':
print((data[i])[j])
print([k for k in (data['releases'])])
except:
print('something went south !!!!!!!!!!')

Related

Call speedtest.Speedtest() from Python using --secure (to avoid speedtest.ConfigRetrievalError: HTTP Error 403: Forbidden)

I have a small Python3-script like this:
import speedtest
# Speedtest
test = speedtest.Speedtest() # <--- line 4
test.get_servers()
best = test.get_best_server()
print(f"Found: {best['host']} located in {best['country']}")
The first time I run it, it works and everything is fine; it outputs:
Found: speedtest.witcom.cloud:8080 located in Germany
Happy days.
The second time (and subsequel times) that I run the script, I get this error:
Traceback (most recent call last):
File "/Users/zeth/Code/pinger/pinger.py", line 4, in <module>
test = speedtest.Speedtest()
File "/usr/local/lib/python3.9/site-packages/speedtest.py", line 1095, in __init__
self.get_config()
File "/usr/local/lib/python3.9/site-packages/speedtest.py", line 1127, in get_config
raise ConfigRetrievalError(e)
speedtest.ConfigRetrievalError: HTTP Error 403: Forbidden
When Googling around, I saw that I could also call this module straight from the command line, but just running this:
$ speedtest-cli
That gives me the same kind of error:
Retrieving speedtest.net configuration...
Cannot retrieve speedtest configuration
ERROR: HTTP Error 403: Forbidden
But if I run the direct cli-command: speedtest-cli --secure ( docs for the --secure-flag ), then it goes through and outputs this:
Retrieving speedtest.net configuration...
Testing from Deutsche Telekom AG (212.185.228.168)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by hotspot.koeln (Cologne) [3.44 km]: 28.805 ms
Testing download speed................................................................................
Download: 30.01 Mbit/s
Testing upload speed......................................................................................................
Upload: 8.68 Mbit/s
The question
I can't figure out how to change this Python-line: test = speedtest.Speedtest() to use a --secure-flag (nor via HTTPS).
The documentation for speedtest-cli is scarce.
Other attempts
I found this solution here: Python Speedtest facing problems with certification _ssl.c:1056, that suggests manually approving the certificates.
But in this directory: /Volumes/Macintosh HD/Applications/ I don't have anything called Python3.9. I have python3.9 installed via Brew. And I'm on a Mac.
I could do this:
test = speedtest.Speedtest(secure=True)
I looked into the source code myself, in this directory:
vim /usr/local/lib/python3.9/site-packages/speedtest.py
Where I would see the function was defined like this:
class Speedtest(object):
"""Class for performing standard speedtest.net testing operations"""
def __init__(self, config=None, source_address=None, timeout=10,
secure=False, shutdown_event=None):
self.config = {}
self._source_address = source_address
self._timeout = timeout
self._opener = build_opener(source_address, timeout)
self._secure = secure
...
...
...

Python tftp handling error: "No options found in OACK"

I am using python 3's module tftpy to attempt to handle tftp style downloading of a file. However, when I run the application I get the following error:
\Python38\site-packages\tftpy\TftpStates.py", line 53, in handleOACK
raise TftpException("No options found in OACK")
tftpy.TftpShared.TftpException: No options found in OACK
How do I get my python project to ignore OACK/ send a new request packet that doesn't include an OACK?
Disclaimer: This is my first time attempting to work with TFTP packets so I am fairly new. If the question I posed isn't the appropriate way to handle it, what should I be doing?
MORE DATA ON THE PROBLEM:
I am using an external chip that is programmed to ignore OACK packet options.
When I used C# and the TFTP.Net package the transfer worked, so I don't believe it is an issue with my TFTP server. However, as our main application is based in python I want to be able to handle this communication via python 3.
I am running python 3.8.5
On my server side it is saying it receives a packet with error code 8.
python Script:
import tftpy
client = tftpy.TftpClient('192.168.0.42', 69)
client.download('triplog.txt', 'faultlog.txt', packethook=None, timeout=5)
full traceback:
Failed to negotiate options: No options found in OACK
Traceback (most recent call last):
File "C:\Users\selena\Documents\PythonScripts\TFTP\TFTPTestScript.py", line 23, in <module>
client.download('triplog.txt', 'faultlog.txt', packethook=None, timeout=5)
File "C:\Users\selena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tftpy\TftpClient.py", line 58, in download
self.context.start()
File "C:\Users\selena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tftpy\TftpContexts.py", line 402, in start
self.cycle()
File "C:\Users\selena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tftpy\TftpContexts.py", line 202, in cycle
self.state = self.state.handle(recvpkt, raddress, rport)
File "C:\Users\selena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tftpy\TftpStates.py", line 566, in handle
self.handleOACK(pkt)
File "C:\Users\selena\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\tftpy\TftpStates.py", line 53, in handleOACK
raise TftpException("No options found in OACK")
tftpy.TftpShared.TftpException: No options found in OACK
[Finished in 0.7s with exit code 1]
Credit #ewong for this workaround solution
The code worked after adding in options when initializing the client even though I didn't need them. I'll be filing an issue #https://github.com/msoulier/tftpy to see if this is a bug that needs to be addressed or a deliberate choice.
Solution code:
import tftpy
client = tftpy.TftpClient('192.168.0.42', 69, options={'blksize': 8})
client.download('triplog.txt', 'faultlog.txt', packethook=None, timeout=5)

WSAStartup error (10093) when calling exiftool through PyExifTool

I have installed PyExifTool (https://smarnach.github.io/pyexiftool/). The installation was successful. However, when I try to run the example code provided there:
import exiftool
files = ["test.jpg"]
with exiftool.ExifTool() as et:
metadata = et.get_metadata_batch(files)
for d in metadata:
print("{:20.20} {:20.20}".format(d["SourceFile"],
d["EXIF:DateTimeOriginal"]))
I am getting this error:
Traceback (most recent call last):
File "extract_metadata_03.py", line 5, in <module>
metadata = et.get_metadata_batch(files)
File "c:\Python38\lib\site-packages\exiftool.py", line 264, in get_metadata_batch
return self.execute_json(*filenames)
File "c:\Python38\lib\site-packages\exiftool.py", line 256, in execute_json
return json.loads(self.execute(b"-j", *params).decode("utf-8"))
File "c:\Python38\lib\site-packages\exiftool.py", line 227, in execute
inputready,outputready,exceptready = select.select([fd],[],[])
OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed
I have tried with exiftool.exe Version 11.91 stand-alone Windows executable (from https://exiftool.org/) in my path as well as installing exiftool using Oliver Betz's ExifTool Windows installer (https://oliverbetz.de/pages/Artikel/ExifTool-for-Windows)
I have tried two separate Python installations (Python 3.8 and also Python 2.7) with the same behaviour.
Any assistance with this or suggestions for troubleshooting would be greatly appreciated.
You get the error because the select.select() used in exiftool.py is not compatible with Windows. To solve this you can manually add the following to exiftool.py:
if sys.platform == 'win32':
# windows does not support select() for anything except sockets
# https://docs.python.org/3.7/library/select.html
output += os.read(fd, block_size)
else:
# this does NOT work on windows... and it may not work on other systems... in that case, put more things to use the original code above
inputready,outputready,exceptready = select.select([fd],[],[])
for i in inputready:
if i == fd:
output += os.read(fd, block_size)
Source: https://github.com/sylikc/pyexiftool/commit/03a8595a2eafc61ac21deaa1cf5e109c6469b17c

CS50 Finance - NameError: name 'self' is not defined

I am getting 500 Internal Server Error when running flask with the following error message:
NameError: name 'self' is not defined
Yesterday my code worked fine and I didn't make any changes. The error message lists python files which were already imported in the distribution code. Maybe something changed in the background?
192.168.234.116 - - [10/Jul/2019 11:15:56] "GET / HTTP/1.0" 500 -
Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/werkzeug/serving.py", line 303, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python3.7/site-packages/werkzeug/serving.py", line 291, in execute
application_iter = app(environ, start_response)
File "/home/ubuntu/environment/pset8/finance/application.py", line 13, in <module>
app = Flask(__name__)
File "/usr/local/lib/python3.7/site-packages/cs50/flask.py", line 54, in _after
self.wsgi_app = ProxyFix(self.wsgi_app, x_proto=1)
NameError: name 'self' is not defined
It's a CS50 bug (regression).
I've submitted [GitHub]: cs50/python-cs50 - Added the 1st (required) argument (self) to flask.Flask's initializer, which was closed (because it was incomplete - as I was too rushed when submitting it, and missed one spot), and [GitHub]: Fix missing self arguments in Flask __init__ replacement was created and merged. Not sure though when will it be available on the market (PyPI, so you can simply pip install it), but you could download the sources from GitHub and overwrite yours.
As an alternative, you could download the patch, and apply the changes locally. Check [SO]: Run/Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (basically, every line that starts with one "+" sign goes in, and every line that starts with one "-" sign goes out). Or (given the fact that the change is more than trivial), you could:
Open the flask.py file (in your case: "/usr/local/lib/python3.7/site-packages/cs50/flask.py") in a text editor
Go to line #54 (in your case, in mine it's 52)
Replace the current content (do not alter leading SPACEs):
For the current line (def _after(*args, **kwargs):) by: def _after(self, *args, **kwargs):
For the next one (_before(*args, **kwargs)) by: _before(self, *args, **kwargs)
#EDIT0:
As #kaczifant already experienced, the fix is already available for download: pip3 install cs50 --upgrade
The bug was fixed by the CS50 staff.
Select CS50 IDE > Log Out and then log back in at ide.cs50.io. Alternatively, you can run:
sudo pip3 install cs50 --upgrade

RPC Error when using jnpr.junos.utils.config Load command

still rather new to Python. I've been referencing a few blogs regarding the jnpr.junos packages. Specifically from Jeremy Schulman (http://forums.juniper.net/t5/Automation/Python-for-Non-Programmers-Part-2/bc-p/277682). I'm simply trying to make sure I have the commands right. I'm just attempting to pass simple commands to my SRX cluster. I'm attempting to pass the following to an SRX650 cluster.
>>> from jnpr.junos.utils.config import Config
>>> from jnpr.junos import Device
>>> dev = Device(host='devip',user='myuser',password='mypwd')
>>> dev.open()
Device(devip)
>>> cu = Config(dev)
>>> cu
jnpr.junos.utils.Config(devip)
>>> set_cmd = 'set system login message "Hello Admin!"'
>>> cu.load(set_cmd,format='set')
Warning (from warnings module):
File "C:\Python27\lib\site-packages\junos_eznc-1.0.0- py2.7.egg\jnpr\junos\utils\config.py", line 273
if any([e.find('[error-severity="error"]') for e in rerrs]):
FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
cu.load(set_cmd,format='set')
File "C:\Python27\lib\site-packages\junos_eznc-1.0.0- py2.7.egg\jnpr\junos\utils\config.py", line 296, in load
return try_load(rpc_contents, rpc_xattrs)
File "C:\Python27\lib\site-packages\junos_eznc-1.0.0-py2.7.egg\jnpr\junos\utils\config.py", line 274, in try_load
raise err
RpcError
I've done quite a bit of searching and can't seem to find anything as to why this RPC error is popping up. I've confirmed that the syntax is correct and read through the jnpr.junos documentation for Junos EZ.
Found that I was using an outdated version of junos.eznc. Running pip install -U junos-eznc updated me to junos.eznc 1.3.1. After doing this, my script worked properly.

Categories