Closed jingjingwang closed 7 years ago
I will look into this tomorrow.
Best,
Jamone
On Jan 21, 2017, at 9:16 PM, jingjingwang notifications@github.com wrote:
The doc says it's written in Python 2 but places such as this uses urllib.request.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
jingjingwang,
I noticed that the code uses raw_input() instead of input(). raw_input() does not exist in Python 3. That how I came to that conclusion. However, you are correct as I verified urllib.request to be a Python 3 only feature.
It appears that the code is inconsistent with either Python 2 or 3. What version of Python should we stick to? If it's Python 3, then we should definitely remove my comment and make the appropriate changes.
Here are some places in the code that are Python 2:
- username = raw_input("Username: ")
+ username = input("Username: ")
- data = urllib.urlencode({"password" : self.password, "username" : self.username})
+ data = urllib.parse.urlencode({"password" : self.password, "username" : self.username})
- stock = raw_input("Symbol: ");
+ stock = input("Symbol: ");
- print(data["symbol"] + ": $" + data["last_trade_price"]);
+ print((data["symbol"] + ": $" + data["last_trade_price"]));
- urllib.unquote(instrument['url']),
+ urllib.parse.unquote(instrument['url']),
I tested this using Mac OS X Python 2.7 and Python 3.5.2.
Hi guys,
I also tried to execute this script. I received same error. I used Python2.7 and CentOS7.
[irudziankou@localhost Robinhood]$ python example.py Traceback (most recent call last): File "example.py", line 4, in <module> my_trader = Robinhood(); File "/home/irudziankou/Robinhood/Robinhood.py", line 52, in __init__ self.session.proxies = urllib.request.getproxies() AttributeError: 'module' object has no attribute 'request'
Okay. I just used the 2to3 tool to convert to Python 3 and remove the commentary about making the conversion. I issued a pull request to make these changes.
in Version 2.7: I made it urllib.getproxies() instead of urllib.request.getproxies(). And this worked.
@maddurup , It's also working for me. Thanks!
Same problem related to this issue:
>>> my_trader.print_quote("AAPL")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Robinhood.py", line 128, in print_quote
data = self.quote_data(stock)
File "Robinhood.py", line 102, in quote_data
res = json.loads((urllib.request.urlopen(url)).read().decode('utf-8'));
AttributeError: 'module' object has no attribute 'request'
I decided to revert the code to Python 2. A new pull request has been made.
If any of you wish to use Python 3, please read the Pull Request Note.
We will maintain 2 branches for Python 2.7 and 3.
The doc says it's written in Python 2 but places such as this uses
urllib.request
.