import requests
response = requests.post('https://api.github.com/user/repos')
Simple code just to test that requests are working.
I get the following errors.
\User\PycharmProjects\2\venv\Scripts\python.exe C:/Users/User/PycharmProjects/2/101_gui/test.py
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/2/101_gui/test.py", line 3, in <module>
response = requests.post('https://api.github.com/user/repos')
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\api.py", line 87, in post
return request('post', url, data=data, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\adapters.py", line 174, in send
timeout=timeout
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 417, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 232, in _get_conn
return conn or self._new_conn()
File "C:\Users\User\PycharmProjects\2\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 547, in _new_conn
strict=self.strict)
TypeError: __init__() got an unexpected keyword argument 'strict'
Process finished with exit code 1
I am trying to figure out why I cannot at all connect to my bit bucket server, using stashy, using any other lib, even having trouble with calls requests's
Your code works on my machine.
You should try upgrading the requests module by using pip upgrade.
After executing your source code I have no problem executing it accordingly. I think you need to update your request library. Here's how to do that:
https://realpython.com/python-requests/
Related
I'm trying to connect to a website with a proxy. But when I use the code below I get an error. I tried changing http to https. I tried different proxies. But non of them solved my issue.
import requests
proxies = {"http": "http://91.93.135.113:8080"}
requests.get("http://ifconfig.me/ip", proxies=proxies).content
Output:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 412, in send
conn = self.get_connection(request.url, proxies)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 305, in get_connection
proxy_url = parse_url(proxy)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\url.py", line 392, in parse_url
return six.raise_from(LocationParseError(source_url), None)
File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: http://46.197.209.217:3128
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 414, in send
raise InvalidURL(e, request=request)
requests.exceptions.InvalidURL: Failed to parse: http://46.197.209.217:3128
Try using Burp Proxy!
I just change Burp Options on Proxy Label to bind all interfaces (0.0.0.0) and it works with your code.
I am attempting to make a GUI program that will push changes to a Bit Bucket Repository. I have the following code for a TKinter GUI application Button. i keep getting the following errors. Right now I just want to display the repos in the text box that I have also created, but I think I am getting Timeout issues right now? If I am reading the debug log correctly.
def bitbucket_pull():
bitbucket = stashy.connect("https://bitbucket.domain.com:port/projects/blahblah/repos/123/",username, password)
print("""Bitbucket Pull
""")
T.insert(END, bitbucket.projects.list())
but i keep getting this error
Bitbucket Pull
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/user/PycharmProjects/Project/project_gui/main.py", line 118, in bitbucket_pull
T.insert(END, bitbucket.projects.list())
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\stashy\helpers.py", line 78, in list
return list(self.all())
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\stashy\helpers.py", line 44, in paginate
response = self._client.get(url, **kw)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\stashy\client.py", line 59, in get
return requests.get(self.url(resource), auth=(self._username, self._password), verify=self._verify, **kw)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\adapters.py", line 174, in send
timeout=timeout
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 417, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 232, in _get_conn
return conn or self._new_conn()
File "C:\Users\user\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 547, in _new_conn
strict=self.strict)
TypeError: __init__() got an unexpected keyword argument 'strict'
Since it automatically gives me this error (without any kind of hang), I am assuming that its not actually trying the connection and I have wrote the code wrong, or its timing out immediately.
EDIT: No GUI (new file: test_no_gui.py)
import stashy
bitbucket = stashy.connect("https://bitbucket.domain.come:port/projects/asdasd/asd/asdadasd/", "username","password")
print(bitbucket.projects.list())
Still gives this error
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Project/ProjectName/test_no_gui.py", line 3, in <module>
print(bitbucket.projects.list())
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\stashy\helpers.py", line 78, in list
return list(self.all())
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\stashy\helpers.py", line 44, in paginate
response = self._client.get(url, **kw)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\stashy\client.py", line 59, in get
return requests.get(self.url(resource), auth=(self._username, self._password), verify=self._verify, **kw)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\adapters.py", line 174, in send
timeout=timeout
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 417, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 232, in _get_conn
return conn or self._new_conn()
File "C:\Users\User\PycharmProjects\Project\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 547, in _new_conn
strict=self.strict)
TypeError: __init__() got an unexpected keyword argument 'strict'
Upgraded all libs, did not use stashy, used requests and worked fine.
If you are using requests library and getting the same error, also upgrade requests. Make sure you are using the latest versions of libs, or you will get the same error and be stuck. Was stuck on this for a few days, as everyone kept telling me to look # the error, but the error did not provide anything meaningful to give me any hints. I seem to have been very very confused, but upgrading the libraries again fixed my issues, only wish we had more verbose error logging for version controls of libraries.
I've created a nameko service that sends a text message to the provided phone number. Using the Africas Talking API. The service runs successfully but once you use the nameko shell it doesn't work. However the phone number is successfully passed into the service.
Nameko Shell:
>>> n.rpc.sms.text('+254712619789')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nameko/rpc.py", line 369, in __call__
return reply.result()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nameko/rpc.py", line 327, in result
raise deserialize(error)
nameko.exceptions.RemoteError: TypeError GreenSSLSocket does not have a public constructor. Instances are returned by SSLContext.wrap_socket().
Nameko Service
nameko run at
starting services: sms
Connected to amqp://guest:**#127.0.0.1:5672//
+254712619789
error handling worker <WorkerContext [sms.text] at 0x10414a128>: GreenSSLSocket does not have a public constructor. Instances are returned by SSLContext.wrap_socket().
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nameko/containers.py", line 391, in _run_worker
result = method(*worker_ctx.args, **worker_ctx.kwargs)
File "./at.py", line 23, in text
response = sms.send("Hello Message!", [phone_no])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/africastalking/SMS.py", line 32, in send
return self._make_request(url, 'POST', headers=self._headers, params=None, data=data, callback=callback)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/africastalking/Service.py", line 92, in _make_request
res = self.__make_post_request(url=url, headers=headers, data=data, params=params)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/africastalking/Service.py", line 78, in __make_post_request
data=data,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connection.py", line 356, in connect
ssl_context=context)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/eventlet/green/ssl.py", line 402, in wrap_socket
return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/eventlet/green/ssl.py", line 68, in __init__
ca_certs, do_handshake_on_connect and six.PY2, *args, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 788, in __init__
f"{self.__class__.__name__} does not have a public "
TypeError: GreenSSLSocket does not have a public constructor. Instances are returned by SSLContext.wrap_socket().
at.py
import json
from nameko.web.handlers import http
from nameko.rpc import rpc
import africastalking
class HttpService(object):
name = "sms"
#rpc
def text(self, phone_no):
print (phone_no)
africastalking.initialize(username, api_key)
# Initialize a service e.g. SMS
sms = africastalking.SMS
# Use the service synchronously
response = sms.send("Hello Message!", [phone_no])
print(response)
return response
the issue might be eventlet not being compatible with python 3.7. Could you try with python 3.6?
(see e.g. https://github.com/eventlet/eventlet/issues/502)
I write a locust script to test a web site.
The script is very simple, just a request repeated several time.
In a virtual machine with Linux Mint and Python 2.7.6, the script works in the right way and as I want.
For example, I run the script without the Web Interface as write below:
locust --no-web -n 10 -c 1 -r 1 -f /path/to/file/file_test.py
and I obtain the right stats in the terminal window.
When I run the same script on another virtual machine with CentOS and Python 2.7.11, I obtain the following error:
[2016-05-20 12:26:03,954] nix/ERROR/stderr: Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 267, in run
self.execute_next_task()
File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 293, in execute_next_task
self.execute_task(task["callable"], *task["args"], **task["kwargs"])
File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 305, in execute_task
task(self, *args, **kwargs)
File "/data/IVV/multi_benchmark/locust_scripts/OD_skip_top_multi_query.py", line 15, in query1
self.client.get(QUERY, verify=False)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 113, in request
response = self._send_request_safe_mode(method, url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 157, in _send_request_safe_mode
return requests.Session.request(self, method, url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 403, in send
timeout=timeout
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 578, in urlopen
chunked=chunked)
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 351, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 814, in _validate_conn
conn.connect()
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'
[2016-05-20 12:26:04,911] nix/INFO/locust.runners: All locusts hatched: MyLocust: 1
[2016-05-20 12:26:04,911] nix/INFO/locust.runners: Resetting stats
Could you please help me understanding the problem?
Thanks very much.
It seems to be a known issue in urllib3, it has nothing to to with your scripts. See https://github.com/shazow/urllib3/issues/482
The requests package in Python seems to reference the incorrect SSL cert in Ubuntu. I'm using requests 2.6.2. The code runs fine on a Mac but fails on Ubuntu. I appreciate any help!
This request:
query_string = https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0
requests.get(query_string, auth=(self.accessid,self.key))
Produces this error output:
Traceback (most recent call last):
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
requests.get('https://lsapi.seomoz.com/linkscape/links/youtube.com?Sort=page_authority&Source=page_to_page&Filter=internal&LinkCols=4&Limit=50&Offset=0')
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/home/mark/venvs/nessus/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: hostname 'lsapi.seomoz.com' doesn't match either of 'incapsula.com', ...
This question boils down to being the same as this one: the version of Python you're using does not support SNI. Follow the advice in this answer.