How do you send an HTTP Get Web Request in Python? [duplicate]

You can use urllib2 import urllib2 content = urllib2.urlopen(some_url).read() print content Also you can use httplib import httplib conn = httplib.HTTPConnection(“www.python.org”) conn.request(“HEAD”,”/index.html”) res = conn.getresponse() print res.status, res.reason # Result: 200 OK or the requests library import requests r = requests.get(‘https://api.github.com/user’, auth=(‘user’, ‘pass’)) r.status_code # Result: 200

Reading large text files with streams in C#

You can improve read speed by using a BufferedStream, like this: using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { } } March 2013 UPDATE I recently wrote code for reading and processing (searching … Read more

Converting file into Base64String and back again

If you want for some reason to convert your file to base-64 string. Like if you want to pass it via internet, etc… you can do this Byte[] bytes = File.ReadAllBytes(“path”); String file = Convert.ToBase64String(bytes); And correspondingly, read back to file: Byte[] bytes = Convert.FromBase64String(b64Str); File.WriteAllBytes(path, bytes);

Does disposing streamreader close the stream?

Yes, StreamReader, StreamWriter, BinaryReader and BinaryWriter all close/dispose their underlying streams when you call Dispose on them. They don’t dispose of the stream if the reader/writer is just garbage collected though – you should always dispose of the reader/writer, preferrably with a using statement. (In fact, none of these classes have finalizers, nor should they … Read more

Should I call Close() or Dispose() for stream objects?

A quick jump into Reflector.NET shows that the Close() method on StreamWriter is: public override void Close() { this.Dispose(true); GC.SuppressFinalize(this); } And StreamReader is: public override void Close() { this.Dispose(true); } The Dispose(bool disposing) override in StreamReader is: protected override void Dispose(bool disposing) { try { if ((this.Closable && disposing) && (this.stream != null)) { … Read more

How to read embedded resource text file

You can use the Assembly.GetManifestResourceStream Method: Add the following usings using System.IO; using System.Reflection; Set property of relevant file: Parameter Build Action with value Embedded Resource Use the following code var assembly = Assembly.GetExecutingAssembly(); var resourceName = “MyCompany.MyProduct.MyFile.txt”; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)