Comments (3)
Hi @haadr, thanks for the report!
Curious, did you happen to try the advice in the Gotchas section of the README? If so, did that assist if your case at all?
from curl-auth-csrf.
Hi and thanks for the response! I feel embarrassed that I didn't notice that section of the readme, however it doesn't seem to help.
For what it's worth, personally, I don't have a problem simply running it with python3 and specifying the encoding manually/in-code.
However I also don't quite understand the python2-related encoding problem either. Setting PYTHONIOENCODING doesn't seem to help (see below). I can't pretend to have much experience when it comes to UTF-8 and python2/3 compatability, but people seem to recommend importing io to get the encoding argument for the open() function.
Another solution that makes the error go away for me is not trying to decode it from UTF-8 when passing it to the file object for writing (I guess it will then just pass what it got from requests? A quick search didn't tell me whether requests defaults to utf8 in this case...)
diff --git a/curl-auth-csrf.py b/curl-auth-csrf.py
index 2a72fa8..16b9f95 100755
--- a/curl-auth-csrf.py
+++ b/curl-auth-csrf.py
@@ -214,7 +214,7 @@ def main():
logging.info('Performing GET on %s ...' % url_after_login)
result = session.get(url_after_login, verify=False, headers={'Referer': result.url, 'User-Agent': args.user_agent_str})
logging.info("Request result = %d", result.status_code)
- args.output.write(result.content.decode('utf-8'))
+ args.output.write(result.content)
#########
# logout
Original error with the environment variable:
21:26:18 bert: curl-auth-csrf $ python2.7 -c "import sys; print sys.stdout.encoding" | cat
None
21:26:26 bert: curl-auth-csrf $ PYTHONIOENCODING=UTF-8 python2.7 -c "import sys; print sys.stdout.encoding" | cat
UTF-8
21:26:43 bert: curl-auth-csrf $ PYTHONIOENCODING=UTF-8 ./curl-auth-csrf.py -i https://<url> -d username=<user> -o user22 https://<url>
Password:
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
Traceback (most recent call last):
File "./curl-auth-csrf.py", line 230, in <module>
main()
File "./curl-auth-csrf.py", line 217, in main
args.output.write(result.content.decode('utf-8'))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 186: ordinal not in range(128)
21:33:51 bert: curl-auth-csrf $ echo $PYTHONIOENCODING
UTF-8
from curl-auth-csrf.
Thanks for the additional info. I'll try to test a few edge cases. I'll report status below when I get to it.
from curl-auth-csrf.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curl-auth-csrf.